]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind-{session,seat}: get rid of basename() in _new() 31594/head
authorMike Yuan <me@yhndnzj.com>
Sat, 2 Mar 2024 15:46:00 +0000 (23:46 +0800)
committerMike Yuan <me@yhndnzj.com>
Sat, 2 Mar 2024 16:00:28 +0000 (00:00 +0800)
src/login/logind-seat.c
src/login/logind-session.c
src/login/logind-session.h

index 21f2c1ddd8016c456e995af6b619a691db54e16b..bed1f7db031f30da52beeeabb66ff9068989fbb4 100644 (file)
@@ -42,14 +42,12 @@ int seat_new(Manager *m, const char *id, Seat **ret) {
 
         *s = (Seat) {
                 .manager = m,
+                .id = strdup(id),
+                .state_file = path_join("/run/systemd/seats/", id),
         };
-
-        s->state_file = path_join("/run/systemd/seats", id);
-        if (!s->state_file)
+        if (!s->id || !s->state_file)
                 return -ENOMEM;
 
-        s->id = basename(s->state_file);
-
         r = hashmap_put(m->seats, s->id, s);
         if (r < 0)
                 return r;
@@ -77,6 +75,7 @@ Seat* seat_free(Seat *s) {
 
         free(s->positions);
         free(s->state_file);
+        free(s->id);
 
         return mfree(s);
 }
index a0dc6265b778774ef80f17aa212e4bef73beb1a1..2713215e10a47aa9b8ced28d22807cc50eb01ca8 100644 (file)
@@ -63,19 +63,17 @@ int session_new(Manager *m, const char *id, Session **ret) {
 
         *s = (Session) {
                 .manager = m,
+                .id = strdup(id),
+                .state_file = path_join("/run/systemd/sessions/", id),
                 .fifo_fd = -EBADF,
                 .vtfd = -EBADF,
                 .audit_id = AUDIT_SESSION_INVALID,
                 .tty_validity = _TTY_VALIDITY_INVALID,
                 .leader = PIDREF_NULL,
         };
-
-        s->state_file = path_join("/run/systemd/sessions", id);
-        if (!s->state_file)
+        if (!s->id || !s->state_file)
                 return -ENOMEM;
 
-        s->id = basename(s->state_file);
-
         s->devices = hashmap_new(&devt_hash_ops);
         if (!s->devices)
                 return -ENOMEM;
@@ -146,10 +144,12 @@ Session* session_free(Session *s) {
         if (!s)
                 return NULL;
 
+        sd_event_source_unref(s->stop_on_idle_event_source);
+
         if (s->in_gc_queue)
                 LIST_REMOVE(gc_queue, s->manager->session_gc_queue, s);
 
-        s->timer_event_source = sd_event_source_unref(s->timer_event_source);
+        sd_event_source_unref(s->timer_event_source);
 
         session_drop_controller(s);
 
@@ -203,10 +203,9 @@ Session* session_free(Session *s) {
 
         /* Note that we remove neither the state file nor the fifo path here, since we want both to survive
          * daemon restarts */
-        free(s->state_file);
         free(s->fifo_path);
-
-        sd_event_source_unref(s->stop_on_idle_event_source);
+        free(s->state_file);
+        free(s->id);
 
         return mfree(s);
 }
index 0b84e043fd6b991e4132ccecb484a18072cb8ce5..c187bcd779930c7d189e9b682b4c9398a3453f4e 100644 (file)
@@ -95,7 +95,8 @@ typedef enum TTYValidity {
 struct Session {
         Manager *manager;
 
-        const char *id;
+        char *id;
+
         unsigned position;
         SessionType type;
         SessionType original_type;