tree-wide: make use of wait_for_terminate_and_check() at various places

Using wait_for_terminate_and_check() instead of wait_for_terminate()
let's us simplify, shorten and unify the return value checking and
logging of waitid().  Hence, let's use it all over the place.
This commit is contained in:
Lennart Poettering
2018-01-04 13:27:27 +01:00
parent 1f5d1e0247
commit 2e87a1fde9
11 changed files with 64 additions and 124 deletions
+13 -20
View File
@@ -6065,7 +6065,6 @@ static int enable_sysv_units(const char *verb, char **args) {
_cleanup_free_ char *p = NULL, *q = NULL, *l = NULL;
bool found_native = false, found_sysv;
siginfo_t status;
const char *name;
unsigned c = 1;
pid_t pid;
@@ -6129,27 +6128,21 @@ static int enable_sysv_units(const char *verb, char **args) {
_exit(EXIT_FAILURE);
}
j = wait_for_terminate(pid, &status);
j = wait_for_terminate_and_check("sysv-install", pid, WAIT_LOG_ABNORMAL);
if (j < 0)
return log_error_errno(j, "Failed to wait for child: %m");
return j;
if (streq(verb, "is-enabled")) {
if (j == 0) {
if (!arg_quiet)
puts("enabled");
r = 1;
} else {
if (!arg_quiet)
puts("disabled");
}
if (status.si_code == CLD_EXITED) {
if (streq(verb, "is-enabled")) {
if (status.si_status == 0) {
if (!arg_quiet)
puts("enabled");
r = 1;
} else {
if (!arg_quiet)
puts("disabled");
}
} else if (status.si_status != 0)
return -EBADE; /* We don't warn here, under the assumption the script already showed an explanation */
} else {
log_error("Unexpected waitid() result.");
return -EPROTO;
}
} else if (j != 0)
return -EBADE; /* We don't warn here, under the assumption the script already showed an explanation */
if (found_native)
continue;