From 26ed3ecfe0c48a9709da608a0e18308ba7c8fa20 Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Tue, 12 Mar 2024 10:39:08 +0100 Subject: [PATCH 1/2] logind: place 'ret' param at last Follow-up to 2454cee32e --- src/login/logind-core.c | 2 +- src/login/logind-inhibit.c | 4 ++-- src/login/logind-inhibit.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 54febdadd7..d20ff3d4d4 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -221,7 +221,7 @@ int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret) { i = hashmap_get(m->inhibitors, id); if (!i) { - r = inhibitor_new(&i, m, id); + r = inhibitor_new(m, id, &i); if (r < 0) return r; } diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 7591bce08c..e2421ef9d2 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) diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index c34c225676..15cbbb6cc7 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -51,7 +51,7 @@ struct Inhibitor { int fifo_fd; }; -int inhibitor_new(Inhibitor **ret, Manager *m, const char* id); +int inhibitor_new(Manager *m, const char* id, Inhibitor **ret); Inhibitor* inhibitor_free(Inhibitor *i); DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free); From af9f57e731b5ad0421ac8ab76c2818569d7c984a Mon Sep 17 00:00:00 2001 From: Antonio Alvarez Feijoo Date: Tue, 12 Mar 2024 10:43:31 +0100 Subject: [PATCH 2/2] logind-inhibit: get rid of basename() in inhibitor_new() Follow-up to #31594 --- src/login/logind-inhibit.c | 10 +++++----- src/login/logind-inhibit.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index e2421ef9d2..203665ca3c 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -43,6 +43,8 @@ int inhibitor_new(Manager *m, const char* id, Inhibitor **ret) { *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(Manager *m, const char* id, Inhibitor **ret) { .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); diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index 15cbbb6cc7..8f822ded04 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -32,7 +32,7 @@ struct Inhibitor { sd_event_source *event_source; - const char *id; + char *id; char *state_file; bool started;