From: Lennart Poettering Date: Wed, 3 Nov 2021 14:56:09 +0000 (+0100) Subject: tree-wide: port various places to use TAKE_PID() X-Git-Tag: v250-rc1~364^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f03de5323c86f2e7ce0884e169e2c7180938fbd;p=thirdparty%2Fsystemd.git tree-wide: port various places to use TAKE_PID() --- diff --git a/src/core/execute.c b/src/core/execute.c index bf4a66e3bd5..d8bbc694b46 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2248,8 +2248,7 @@ static int setup_private_users(uid_t ouid, gid_t ogid, uid_t uid, gid_t gid) { if (n != 0) /* on success we should have read 0 bytes */ return -EIO; - r = wait_for_terminate_and_check("(sd-userns)", pid, 0); - pid = 0; + r = wait_for_terminate_and_check("(sd-userns)", TAKE_PID(pid), 0); if (r < 0) return r; if (r != EXIT_SUCCESS) /* If something strange happened with the child, let's consider this fatal, too */ diff --git a/src/core/mount.c b/src/core/mount.c index c4d7f981c6d..321c7986b3c 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -236,8 +236,7 @@ static void mount_unwatch_control_pid(Mount *m) { if (m->control_pid <= 0) return; - unit_unwatch_pid(UNIT(m), m->control_pid); - m->control_pid = 0; + unit_unwatch_pid(UNIT(m), TAKE_PID(m->control_pid)); } static void mount_parameters_done(MountParameters *p) { diff --git a/src/core/service.c b/src/core/service.c index 16d94567196..4b99311e5ac 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -130,8 +130,7 @@ static void service_unwatch_control_pid(Service *s) { if (s->control_pid <= 0) return; - unit_unwatch_pid(UNIT(s), s->control_pid); - s->control_pid = 0; + unit_unwatch_pid(UNIT(s), TAKE_PID(s->control_pid)); } static void service_unwatch_main_pid(Service *s) { @@ -140,8 +139,7 @@ static void service_unwatch_main_pid(Service *s) { if (s->main_pid <= 0) return; - unit_unwatch_pid(UNIT(s), s->main_pid); - s->main_pid = 0; + unit_unwatch_pid(UNIT(s), TAKE_PID(s->main_pid)); } static void service_unwatch_pid_file(Service *s) { diff --git a/src/core/socket.c b/src/core/socket.c index 81178e3de26..ba3df329977 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -109,8 +109,7 @@ static void socket_unwatch_control_pid(Socket *s) { if (s->control_pid <= 0) return; - unit_unwatch_pid(UNIT(s), s->control_pid); - s->control_pid = 0; + unit_unwatch_pid(UNIT(s), TAKE_PID(s->control_pid)); } static void socket_cleanup_fd_list(SocketPort *p) { diff --git a/src/core/swap.c b/src/core/swap.c index 29c63118ac6..de72ac9232a 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -155,8 +155,7 @@ static void swap_unwatch_control_pid(Swap *s) { if (s->control_pid <= 0) return; - unit_unwatch_pid(UNIT(s), s->control_pid); - s->control_pid = 0; + unit_unwatch_pid(UNIT(s), TAKE_PID(s->control_pid)); } static void swap_done(Unit *u) { diff --git a/src/import/export-tar.c b/src/import/export-tar.c index b734c3004a7..6dc2e017331 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -147,8 +147,7 @@ static int tar_export_finish(TarExport *e) { assert(e->tar_fd >= 0); if (e->tar_pid > 0) { - r = wait_for_terminate_and_check("tar", e->tar_pid, WAIT_LOG); - e->tar_pid = 0; + r = wait_for_terminate_and_check("tar", TAKE_PID(e->tar_pid), WAIT_LOG); if (r < 0) return r; if (r != EXIT_SUCCESS) diff --git a/src/import/import-tar.c b/src/import/import-tar.c index bb67862d620..c8916da11a3 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -167,8 +167,7 @@ static int tar_import_finish(TarImport *i) { i->tar_fd = safe_close(i->tar_fd); if (i->tar_pid > 0) { - r = wait_for_terminate_and_check("tar", i->tar_pid, WAIT_LOG); - i->tar_pid = 0; + r = wait_for_terminate_and_check("tar", TAKE_PID(i->tar_pid), WAIT_LOG); if (r < 0) return r; if (r != EXIT_SUCCESS) diff --git a/src/import/pull-common.c b/src/import/pull-common.c index 39067933b5e..adb366222da 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -482,8 +482,7 @@ static int verify_gpg( gpg_pipe[1] = safe_close(gpg_pipe[1]); - r = wait_for_terminate_and_check("gpg", pid, WAIT_LOG_ABNORMAL); - pid = 0; + r = wait_for_terminate_and_check("gpg", TAKE_PID(pid), WAIT_LOG_ABNORMAL); if (r < 0) goto finish; if (r != EXIT_SUCCESS) diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index 06d336bca91..bce49cf4e52 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -369,8 +369,7 @@ static void tar_pull_job_on_finished(PullJob *j) { pull_job_close_disk_fd(i->settings_job); if (i->tar_pid > 0) { - r = wait_for_terminate_and_check("tar", i->tar_pid, WAIT_LOG); - i->tar_pid = 0; + r = wait_for_terminate_and_check("tar", TAKE_PID(i->tar_pid), WAIT_LOG); if (r < 0) goto finish; if (r != EXIT_SUCCESS) { diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 96d5b9605e0..9ebf7b03c01 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -1082,10 +1082,10 @@ static int bus_parse_next_address(sd_bus *b) { } static void bus_kill_exec(sd_bus *bus) { - if (pid_is_valid(bus->busexec_pid) > 0) { - sigterm_wait(bus->busexec_pid); - bus->busexec_pid = 0; - } + if (!pid_is_valid(bus->busexec_pid)) + return; + + sigterm_wait(TAKE_PID(bus->busexec_pid)); } static int bus_start_address(sd_bus *b) { diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 8c0bc99d727..09c79b22e70 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5248,8 +5248,7 @@ static int run_container( } } - r = wait_for_container(*pid, &container_status); - *pid = 0; + r = wait_for_container(TAKE_PID(*pid), &container_status); /* Tell machined that we are gone. */ if (bus) diff --git a/src/shared/pager.c b/src/shared/pager.c index 90c347f8c0d..54180653336 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -286,7 +286,7 @@ void pager_close(void) { stdout_redirected = stderr_redirected = false; (void) kill(pager_pid, SIGCONT); - (void) wait_for_terminate(pager_pid, NULL); + (void) wait_for_terminate(TAKE_PID(pager_pid), NULL); pager_pid = 0; } diff --git a/src/shared/spawn-ask-password-agent.c b/src/shared/spawn-ask-password-agent.c index 38fab212034..902d7543a59 100644 --- a/src/shared/spawn-ask-password-agent.c +++ b/src/shared/spawn-ask-password-agent.c @@ -43,9 +43,7 @@ void ask_password_agent_close(void) { return; /* Inform agent that we are done */ - (void) kill_and_sigcont(agent_pid, SIGTERM); - (void) wait_for_terminate(agent_pid, NULL); - agent_pid = 0; + sigterm_wait(TAKE_PID(agent_pid)); } int ask_password_agent_open_if_enabled(BusTransport transport, bool ask_password) { diff --git a/src/shared/spawn-polkit-agent.c b/src/shared/spawn-polkit-agent.c index cd0b4601da1..7fa75081783 100644 --- a/src/shared/spawn-polkit-agent.c +++ b/src/shared/spawn-polkit-agent.c @@ -69,9 +69,7 @@ void polkit_agent_close(void) { return; /* Inform agent that we are done */ - (void) kill_and_sigcont(agent_pid, SIGTERM); - (void) wait_for_terminate(agent_pid, NULL); - agent_pid = 0; + sigterm_wait(TAKE_PID(agent_pid)); } #else