summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-08-31 18:50:11 +0200
committerGitHub <noreply@github.com>2017-08-31 18:50:11 +0200
commit99f5f8e256600fb143b1c0d6b1a0813d02f4d9c7 (patch)
tree6678061ba9fbd8508baf7de42a96c2f837934f7a
parente8deb9486fe01258091acb3f4d614fc60e82e5dd (diff)
parentae835bc75f7ebaec1a685259be3a26503bf81d24 (diff)
downloadsystemd-99f5f8e256600fb143b1c0d6b1a0813d02f4d9c7.tar.gz
Merge pull request #6708 from poettering/job-result-fixes
minor fixes, in particular to job state display in systemctl
-rw-r--r--src/basic/process-util.c8
-rw-r--r--src/core/dbus-manager.c2
-rw-r--r--src/login/logind-dbus.c4
-rw-r--r--src/machine/machined-dbus.c2
-rw-r--r--src/shared/bus-unit-util.c11
-rw-r--r--src/systemctl/systemctl.c6
6 files changed, 19 insertions, 14 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 056a8b82aa..e4cde6561b 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -475,7 +475,7 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
assert(field);
assert(uid);
- if (pid < 0)
+ if (!pid_is_valid(pid))
return -EINVAL;
p = procfs_file_alloca(pid, "status");
@@ -788,7 +788,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) {
bool pid_is_unwaited(pid_t pid) {
/* Checks whether a PID is still valid at all, including a zombie */
- if (pid < 0)
+ if (!pid_is_valid(pid))
return false;
if (pid <= 1) /* If we or PID 1 would be dead and have been waited for, this code would not be running */
@@ -808,7 +808,7 @@ bool pid_is_alive(pid_t pid) {
/* Checks whether a PID is still valid and not a zombie */
- if (pid < 0)
+ if (!pid_is_valid(pid))
return false;
if (pid <= 1) /* If we or PID 1 would be a zombie, this code would not be running */
@@ -827,7 +827,7 @@ bool pid_is_alive(pid_t pid) {
int pid_from_same_root_fs(pid_t pid) {
const char *root;
- if (pid < 0)
+ if (!pid_is_valid(pid))
return false;
if (pid == 0 || pid == getpid_cached())
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index f87b52a266..c91d56598b 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -446,7 +446,7 @@ static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bu
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return r;
- if (pid < 0)
+ if (!pid_is_valid((pid_t) pid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid);
if (pid == 0) {
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index d66022f802..1aa6760665 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -344,7 +344,7 @@ static int method_get_session_by_pid(sd_bus_message *message, void *userdata, sd
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return r;
- if (pid < 0)
+ if (!pid_is_valid((pid_t) pid))
return -EINVAL;
if (pid == 0) {
@@ -407,7 +407,7 @@ static int method_get_user_by_pid(sd_bus_message *message, void *userdata, sd_bu
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return r;
- if (pid < 0)
+ if (!pid_is_valid((pid_t) pid))
return -EINVAL;
if (pid == 0) {
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index c9b92d2765..6618ec30f1 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -199,7 +199,7 @@ static int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd
if (r < 0)
return r;
- if (pid < 0)
+ if (!pid_is_valid((pid_t) pid))
return -EINVAL;
if (pid == 0) {
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index 98a6ada9f2..c024f64ca9 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -1127,6 +1127,9 @@ static int bus_job_get_service_result(BusWaitForJobs *d, char **result) {
assert(d->name);
assert(result);
+ if (!endswith(d->name, ".service"))
+ return -EINVAL;
+
dbus_path = unit_dbus_path_from_name(d->name);
if (!dbus_path)
return -ENOMEM;
@@ -1224,14 +1227,14 @@ static int check_wait_response(BusWaitForJobs *d, bool quiet, const char* const*
log_error("Operation on or unit type of %s not supported on this system.", strna(d->name));
else if (streq(d->result, "collected"))
log_error("Queued job for %s was garbage collected.", strna(d->name));
- else if (!streq(d->result, "done") && !streq(d->result, "skipped")) {
+ else if (!STR_IN_SET(d->result, "done", "skipped")) {
if (d->name) {
- int q;
_cleanup_free_ char *result = NULL;
+ int q;
q = bus_job_get_service_result(d, &result);
if (q < 0)
- log_debug_errno(q, "Failed to get Result property of service %s: %m", d->name);
+ log_debug_errno(q, "Failed to get Result property of unit %s: %m", d->name);
log_job_error_with_service_result(d->name, result, extra_args);
} else
@@ -1251,7 +1254,7 @@ static int check_wait_response(BusWaitForJobs *d, bool quiet, const char* const*
r = -EPROTO;
else if (streq(d->result, "unsupported"))
r = -EOPNOTSUPP;
- else if (!streq(d->result, "done") && !streq(d->result, "skipped"))
+ else if (!STR_IN_SET(d->result, "done", "skipped"))
r = -EIO;
return r;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index d0c7ed79a3..79e9ac95c1 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3348,8 +3348,10 @@ static int logind_check_inhibitors(enum action a) {
if (!sv)
return log_oom();
- if ((pid_t) pid < 0)
- return log_error_errno(ERANGE, "Bad PID %"PRIu32": %m", pid);
+ if (!pid_is_valid((pid_t) pid)) {
+ log_error("Invalid PID %" PRIu32 ".", pid);
+ return -ERANGE;
+ }
if (!strv_contains(sv,
IN_SET(a,