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:
@@ -1244,7 +1244,6 @@ int dissected_image_acquire_metadata(DissectedImage *m) {
|
||||
_cleanup_free_ char *hostname = NULL;
|
||||
unsigned n_meta_initialized = 0, k;
|
||||
int fds[2 * _META_MAX], r;
|
||||
siginfo_t si;
|
||||
|
||||
BLOCK_SIGNALS(SIGCHLD);
|
||||
|
||||
@@ -1366,15 +1365,12 @@ int dissected_image_acquire_metadata(DissectedImage *m) {
|
||||
}
|
||||
}
|
||||
|
||||
r = wait_for_terminate(child, &si);
|
||||
r = wait_for_terminate_and_check("(sd-dissect)", child, 0);
|
||||
child = 0;
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
child = 0;
|
||||
|
||||
if (si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS) {
|
||||
r = -EPROTO;
|
||||
goto finish;
|
||||
}
|
||||
if (r != EXIT_SUCCESS)
|
||||
return -EPROTO;
|
||||
|
||||
free_and_replace(m->hostname, hostname);
|
||||
m->machine_id = machine_id;
|
||||
|
||||
@@ -1256,7 +1256,6 @@ static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
_cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
|
||||
pid_t pid, child;
|
||||
siginfo_t si;
|
||||
char buf[37];
|
||||
ssize_t k;
|
||||
int r;
|
||||
@@ -1308,9 +1307,11 @@ static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
|
||||
|
||||
pair[1] = safe_close(pair[1]);
|
||||
|
||||
r = wait_for_terminate(child, &si);
|
||||
if (r < 0 || si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS)
|
||||
return r < 0 ? r : -EIO;
|
||||
r = wait_for_terminate_and_check("(sd-bootid)", child, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r != EXIT_SUCCESS)
|
||||
return -EIO;
|
||||
|
||||
k = recv(pair[0], buf, 36, 0);
|
||||
if (k != 36)
|
||||
|
||||
@@ -79,7 +79,6 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
struct statvfs ss;
|
||||
pid_t pid = 0;
|
||||
siginfo_t si;
|
||||
int r;
|
||||
|
||||
/* We want to be able to make use of btrfs-specific file
|
||||
@@ -141,24 +140,19 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
r = wait_for_terminate(pid, &si);
|
||||
r = wait_for_terminate_and_check("mkfs", pid, 0);
|
||||
pid = 0;
|
||||
|
||||
if (r < 0) {
|
||||
sd_bus_error_set_errnof(error, r, "Failed to wait for mkfs.btrfs: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pid = 0;
|
||||
|
||||
if (si.si_code != CLD_EXITED) {
|
||||
r = sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "mkfs.btrfs died abnormally.");
|
||||
goto fail;
|
||||
}
|
||||
if (si.si_status == 99) {
|
||||
if (r == 99) {
|
||||
r = sd_bus_error_set_errnof(error, ENOENT, "Cannot set up /var/lib/machines, mkfs.btrfs is missing");
|
||||
goto fail;
|
||||
}
|
||||
if (si.si_status != 0) {
|
||||
r = sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "mkfs.btrfs failed with error code %i", si.si_status);
|
||||
if (r != EXIT_SUCCESS) {
|
||||
r = sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "mkfs.btrfs failed with error code %i", r);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
+1
-7
@@ -190,7 +190,6 @@ int show_man_page(const char *desc, bool null_stdio) {
|
||||
pid_t pid;
|
||||
size_t k;
|
||||
int r;
|
||||
siginfo_t status;
|
||||
|
||||
k = strlen(desc);
|
||||
|
||||
@@ -218,10 +217,5 @@ int show_man_page(const char *desc, bool null_stdio) {
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
r = wait_for_terminate(pid, &status);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
log_debug("Exit code %i status %i", status.si_code, status.si_status);
|
||||
return status.si_status;
|
||||
return wait_for_terminate_and_check(NULL, pid, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user