diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:42 +0000 |
commit | 78e9bb837c258ac0ec7712b3d612cc2f407e731e (patch) | |
tree | f515d16b6efd858a9aeb5b0ef5d6f90bf288283d /src/userdb/userwork.c | |
parent | Adding debian version 255.5-1. (diff) | |
download | systemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.tar.xz systemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.zip |
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/userdb/userwork.c')
-rw-r--r-- | src/userdb/userwork.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/userdb/userwork.c b/src/userdb/userwork.c index b49dbbd..729a9a1 100644 --- a/src/userdb/userwork.c +++ b/src/userdb/userwork.c @@ -353,9 +353,9 @@ static int vl_method_get_group_record(Varlink *link, JsonVariant *parameters, Va static int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { static const JsonDispatch dispatch_table[] = { - { "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), 0 }, + { "userName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, user_name), 0 }, { "groupName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, group_name), 0 }, - { "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, + { "service", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LookupParameters, service), 0 }, {} }; @@ -425,16 +425,16 @@ static int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, Var JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(last_group_name)))); } -static int process_connection(VarlinkServer *server, int fd) { +static int process_connection(VarlinkServer *server, int _fd) { + _cleanup_close_ int fd = TAKE_FD(_fd); /* always take possession */ _cleanup_(varlink_close_unrefp) Varlink *vl = NULL; int r; r = varlink_server_add_connection(server, fd, &vl); - if (r < 0) { - fd = safe_close(fd); + if (r < 0) return log_error_errno(r, "Failed to add connection: %m"); - } + TAKE_FD(fd); vl = varlink_ref(vl); for (;;) { @@ -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"); } } |