mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
sysupdated: use notify_socket_prepare()
This also make it use autobind notify socket.
This commit is contained in:
@@ -46,7 +46,7 @@ typedef struct Manager {
|
||||
|
||||
Hashmap *polkit_registry;
|
||||
|
||||
sd_event_source *notify_event;
|
||||
char *notify_socket_path;
|
||||
|
||||
RuntimeScope runtime_scope; /* For now only RUNTIME_SCOPE_SYSTEM */
|
||||
} Manager;
|
||||
@@ -456,7 +456,7 @@ static int job_start(Job *j) {
|
||||
};
|
||||
size_t k = 2;
|
||||
|
||||
if (setenv("NOTIFY_SOCKET", "/run/systemd/sysupdate/notify", /* overwrite= */ 1) < 0) {
|
||||
if (setenv("NOTIFY_SOCKET", j->manager->notify_socket_path, /* overwrite= */ 1) < 0) {
|
||||
log_error_errno(errno, "setenv() failed: %m");
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -1637,7 +1637,7 @@ static Manager *manager_free(Manager *m) {
|
||||
hashmap_free(m->jobs);
|
||||
|
||||
m->bus = sd_bus_flush_close_unref(m->bus);
|
||||
sd_event_source_unref(m->notify_event);
|
||||
free(m->notify_socket_path);
|
||||
sd_event_unref(m->event);
|
||||
|
||||
return mfree(m);
|
||||
@@ -1698,11 +1698,6 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void
|
||||
|
||||
static int manager_new(Manager **ret) {
|
||||
_cleanup_(manager_freep) Manager *m = NULL;
|
||||
_cleanup_close_ int notify_fd = -EBADF;
|
||||
static const union sockaddr_union sa = {
|
||||
.un.sun_family = AF_UNIX,
|
||||
.un.sun_path = "/run/systemd/sysupdate/notify",
|
||||
};
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
@@ -1738,35 +1733,15 @@ static int manager_new(Manager **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
notify_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
|
||||
if (notify_fd < 0)
|
||||
return -errno;
|
||||
|
||||
(void) mkdir_parents_label(sa.un.sun_path, 0755);
|
||||
(void) sockaddr_un_unlink(&sa.un);
|
||||
|
||||
if (bind(notify_fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0)
|
||||
return -errno;
|
||||
|
||||
r = setsockopt_int(notify_fd, SOL_SOCKET, SO_PASSCRED, true);
|
||||
r = notify_socket_prepare(
|
||||
m->event,
|
||||
SD_EVENT_PRIORITY_NORMAL,
|
||||
manager_on_notify,
|
||||
m,
|
||||
&m->notify_socket_path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = setsockopt_int(notify_fd, SOL_SOCKET, SO_PASSPIDFD, true);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to enable SO_PASSPIDFD, ignoring: %m");
|
||||
|
||||
r = sd_event_add_io(m->event, &m->notify_event, notify_fd, EPOLLIN, manager_on_notify, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_event_source_set_description(m->notify_event, "notify-socket");
|
||||
|
||||
r = sd_event_source_set_io_fd_own(m->notify_event, true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
TAKE_FD(notify_fd);
|
||||
|
||||
*ret = TAKE_PTR(m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user