#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"
}
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);
}
int session_device_save(SessionDevice *sd) {
- _cleanup_free_ char *m = NULL;
const char *id;
int r;
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;
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. */
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;