]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind-inhibit: get rid of basename() in inhibitor_new() 31729/head
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Tue, 12 Mar 2024 09:43:31 +0000 (10:43 +0100)
committerAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Tue, 12 Mar 2024 09:43:31 +0000 (10:43 +0100)
Follow-up to #31594

src/login/logind-inhibit.c
src/login/logind-inhibit.h

index e2421ef9d2f79e8cad8aa3486ba188c458a543ea..203665ca3c43850a530c4b9a7a0494ae999e55fd 100644 (file)
@@ -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);
 
index 15cbbb6cc77a2d15261de3027dbc32aedd6e56d8..8f822ded04dbbf377126de7b3a259b1853956e2a 100644 (file)
@@ -32,7 +32,7 @@ struct Inhibitor {
 
         sd_event_source *event_source;
 
-        const char *id;
+        char *id;
         char *state_file;
 
         bool started;