diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
commit | fc53809803cd2bc2434e312b19a18fa36776da12 (patch) | |
tree | b4b43bd6538f51965ce32856e9c053d0f90919c8 /src/login/logind-inhibit.c | |
parent | Adding upstream version 255.5. (diff) | |
download | systemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip |
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/login/logind-inhibit.c')
-rw-r--r-- | src/login/logind-inhibit.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 1566dab..203665c 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -29,13 +29,13 @@ static void inhibitor_remove_fifo(Inhibitor *i); -int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) { +int inhibitor_new(Manager *m, const char* id, Inhibitor **ret) { _cleanup_(inhibitor_freep) Inhibitor *i = NULL; int r; - assert(ret); assert(m); assert(id); + assert(ret); i = new(Inhibitor, 1); if (!i) @@ -43,6 +43,8 @@ int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) { *i = (Inhibitor) { .manager = m, + .id = strdup(id), + .state_file = path_join("/run/systemd/inhibit/", id), .what = _INHIBIT_WHAT_INVALID, .mode = _INHIBIT_MODE_INVALID, .uid = UID_INVALID, @@ -50,12 +52,9 @@ int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) { .pid = PIDREF_NULL, }; - i->state_file = path_join("/run/systemd/inhibit", id); - if (!i->state_file) + if (!i->id || !i->state_file) return -ENOMEM; - i->id = basename(i->state_file); - r = hashmap_put(m->inhibitors, i->id, i); if (r < 0) return r; @@ -79,8 +78,9 @@ Inhibitor* inhibitor_free(Inhibitor *i) { /* Note that we don't remove neither the state file nor the fifo path here, since we want both to * survive daemon restarts */ - free(i->state_file); free(i->fifo_path); + free(i->state_file); + free(i->id); pidref_done(&i->pid); @@ -270,7 +270,7 @@ int inhibitor_load(Inhibitor *i) { if (i->fifo_path) { _cleanup_close_ int fd = -EBADF; - /* Let's re-open the FIFO on both sides, and close the writing side right away */ + /* Let's reopen the FIFO on both sides, and close the writing side right away */ fd = inhibitor_create_fifo(i); if (fd < 0) return log_error_errno(fd, "Failed to reopen FIFO: %m"); |