From: Yu Watanabe Date: Mon, 15 Aug 2022 11:05:32 +0000 (+0900) Subject: login: use helper functions for fd store X-Git-Tag: v252-rc1~432^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2720b6f23cbf87235339dd3cec32ab790f1b5bf5;p=thirdparty%2Fsystemd.git login: use helper functions for fd store --- diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index 003dbc0a959..dc6a0d54075 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -10,6 +10,7 @@ #include "alloc-util.h" #include "bus-util.h" +#include "daemon-util.h" #include "fd-util.h" #include "logind-session-dbus.h" #include "logind-session-device.h" @@ -376,19 +377,11 @@ error: } void session_device_free(SessionDevice *sd) { - int r; - assert(sd); /* Make sure to remove the pushed fd. */ - if (sd->pushed_fd) { - r = sd_notifyf(false, - "FDSTOREREMOVE=1\n" - "FDNAME=session-%s-device-%u-%u", - sd->session->id, major(sd->dev), minor(sd->dev)); - if (r < 0) - log_warning_errno(r, "Failed to remove file descriptor from the store, ignoring: %m"); - } + if (sd->pushed_fd) + (void) notify_remove_fd_warnf("session-%s-device-%u-%u", sd->session->id, major(sd->dev), minor(sd->dev)); session_device_stop(sd); session_device_notify(sd, SESSION_DEVICE_RELEASE); @@ -469,7 +462,6 @@ unsigned session_device_try_pause_all(Session *s) { } int session_device_save(SessionDevice *sd) { - _cleanup_free_ char *m = NULL; const char *id; int r; @@ -489,13 +481,7 @@ int session_device_save(SessionDevice *sd) { id = sd->session->id; assert(*(id + strcspn(id, "-\n")) == '\0'); - r = asprintf(&m, "FDSTORE=1\n" - "FDNAME=session-%s-device-%u-%u\n", - id, major(sd->dev), minor(sd->dev)); - if (r < 0) - return r; - - r = sd_pid_notify_with_fds(0, false, m, &sd->fd, 1); + r = notify_push_fdf(sd->fd, "session-%s-device-%u-%u", id, major(sd->dev), minor(sd->dev)); if (r < 0) return r; diff --git a/src/login/logind.c b/src/login/logind.c index d14a17274bb..3a6a6e07488 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -438,7 +438,7 @@ static int deliver_fd(Manager *m, const char *fdname, int fd) { static int manager_attach_fds(Manager *m) { _cleanup_strv_free_ char **fdnames = NULL; - int r, n; + int n; /* Upon restart, PID1 will send us back all fds of session devices that we previously opened. Each * file descriptor is associated with a given session. The session ids are passed through FDNAMES. */ @@ -455,15 +455,9 @@ static int manager_attach_fds(Manager *m) { if (deliver_fd(m, fdnames[i], fd) >= 0) continue; - /* Hmm, we couldn't deliver the fd to any session device object? If so, let's close the fd */ - safe_close(fd); - - /* Remove from fdstore as well */ - r = sd_notifyf(false, - "FDSTOREREMOVE=1\n" - "FDNAME=%s", fdnames[i]); - if (r < 0) - log_warning_errno(r, "Failed to remove file descriptor from the store, ignoring: %m"); + /* Hmm, we couldn't deliver the fd to any session device object? If so, let's close the fd + * and remove it from fdstore. */ + close_and_notify_warn(fd, fdnames[i]); } return 0;