logind-{session,seat}: get rid of basename() in _new()

This commit is contained in:
Mike Yuan
2024-03-03 00:00:28 +08:00
parent 7f9c0c29d0
commit c1f04b83c1
3 changed files with 14 additions and 15 deletions
+4 -5
View 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);
}
+8 -9
View 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);
}
+2 -1
View File
@@ -95,7 +95,8 @@ typedef enum TTYValidity {
struct Session {
Manager *manager;
const char *id;
char *id;
unsigned position;
SessionType type;
SessionType original_type;