diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-12-01 17:16:25 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-12-13 18:00:14 +0100 |
commit | 7c695beadca325345095ecde43b2790c6a03036c (patch) | |
tree | c9f3fe344828d698974cff97b1a8a0109d5e5752 /src/userdb | |
parent | pidref: add pidref_set_parent() for race-freely getting pidref on ppid (diff) | |
download | systemd-7c695beadca325345095ecde43b2790c6a03036c.tar.xz systemd-7c695beadca325345095ecde43b2790c6a03036c.zip |
userwork: port to pidref_set_parent()
Diffstat (limited to 'src/userdb')
-rw-r--r-- | src/userdb/userwork.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/userdb/userwork.c b/src/userdb/userwork.c index b49dbbd523..e9b0ac20e0 100644 --- a/src/userdb/userwork.c +++ b/src/userdb/userwork.c @@ -461,6 +461,7 @@ static int process_connection(VarlinkServer *server, int fd) { static int run(int argc, char *argv[]) { usec_t start_time, listen_idle_usec, last_busy_usec = USEC_INFINITY; _cleanup_(varlink_server_unrefp) VarlinkServer *server = NULL; + _cleanup_(pidref_done) PidRef parent = PIDREF_NULL; unsigned n_iterations = 0; int m, listen_fd, r; @@ -505,6 +506,12 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to disable userdb NSS compatibility: %m"); + r = pidref_set_parent(&parent); + if (r < 0) + return log_error_errno(r, "Failed to acquire pidfd of parent process: %m"); + if (parent.pid == 1) /* We got reparented away from userdbd? */ + return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Parent already died, exiting."); + start_time = now(CLOCK_MONOTONIC); for (;;) { @@ -554,14 +561,11 @@ static int run(int argc, char *argv[]) { return log_error_errno(r, "Failed to test for POLLIN on listening socket: %m"); if (FLAGS_SET(r, POLLIN)) { - pid_t parent; - - parent = getppid(); - if (parent <= 1) - return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Parent already died?"); - - if (kill(parent, SIGUSR2) < 0) - return log_error_errno(errno, "Failed to kill our own parent: %m"); + r = pidref_kill(&parent, SIGUSR2); + if (r == -ESRCH) + return log_error_errno(r, "Parent already died?"); + if (r < 0) + return log_error_errno(r, "Failed to send SIGUSR2 signal to parent: %m"); } } |