From: Antonio Alvarez Feijoo Date: Tue, 12 Mar 2024 09:43:31 +0000 (+0100) Subject: logind-inhibit: get rid of basename() in inhibitor_new() X-Git-Tag: v256-rc1~554^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af9f57e731b5ad0421ac8ab76c2818569d7c984a;p=thirdparty%2Fsystemd.git logind-inhibit: get rid of basename() in inhibitor_new() Follow-up to #31594 --- diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index e2421ef9d2f..203665ca3c4 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 15cbbb6cc77..8f822ded04d 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;