1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

util: rework sigkill_wait() to not require pid_t pointer

Let's make sigkill_wait() take a normal pid_t, and add sigkill_waitp() that
takes a pointer (which is useful for usage in _cleanup_), following the usual
logic we have for this.
This commit is contained in:
Lennart Poettering 2016-04-29 19:23:23 +02:00
parent 5659958529
commit 89c9030d31
5 changed files with 14 additions and 8 deletions

View File

@ -528,14 +528,20 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_cod
return -EPROTO;
}
void sigkill_wait(pid_t *pid) {
void sigkill_wait(pid_t pid) {
assert(pid > 1);
if (kill(pid, SIGKILL) > 0)
(void) wait_for_terminate(pid, NULL);
}
void sigkill_waitp(pid_t *pid) {
if (!pid)
return;
if (*pid <= 1)
return;
if (kill(*pid, SIGKILL) > 0)
(void) wait_for_terminate(*pid, NULL);
sigkill_wait(*pid);
}
int kill_and_sigcont(pid_t pid, int sig) {

View File

@ -58,8 +58,8 @@ int get_process_ppid(pid_t pid, pid_t *ppid);
int wait_for_terminate(pid_t pid, siginfo_t *status);
int wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_code);
void sigkill_wait(pid_t *pid);
#define _cleanup_sigkill_wait_ _cleanup_(sigkill_wait)
void sigkill_wait(pid_t pid);
void sigkill_waitp(pid_t *pid);
int kill_and_sigcont(pid_t pid, int sig);

View File

@ -330,7 +330,7 @@ int pull_verify(PullJob *main_job,
_cleanup_close_ int sig_file = -1;
const char *p, *line;
char sig_file_path[] = "/tmp/sigXXXXXX", gpg_home[] = "/tmp/gpghomeXXXXXX";
_cleanup_sigkill_wait_ pid_t pid = 0;
_cleanup_(sigkill_waitp) pid_t pid = 0;
bool gpg_home_created = false;
int r;

View File

@ -166,7 +166,7 @@ int bus_image_method_clone(
r = operation_new(m, child, message, errno_pipe_fd[0]);
if (r < 0) {
(void) sigkill_wait(&child);
(void) sigkill_wait(child);
return r;
}

View File

@ -104,7 +104,7 @@ Operation *operation_free(Operation *o) {
safe_close(o->errno_fd);
if (o->pid > 1)
(void) sigkill_wait(&o->pid);
(void) sigkill_wait(o->pid);
sd_bus_message_unref(o->message);