From 973527648b216bd8a022106e76d1c91cf2e73938 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 25 Apr 2023 12:02:32 +0200 Subject: [PATCH] logind: always use 64bit session IDs it's a bit confusing that on 32bit systems we'd risk session IDs overruns like this. Let's expose the same behaviour everywhere and stick to 64bit ids. Since we format the ids as strings anyway this doesn't really change anything performance-wise, it just pushes out collisions by overrun to basically never happen. --- src/login/logind-dbus.c | 4 ++-- src/login/logind.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 1c151021c7..c5e0fda5e5 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -867,7 +867,7 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus do { id = mfree(id); - if (asprintf(&id, "c%lu", ++m->session_counter) < 0) + if (asprintf(&id, "c%" PRIu64, ++m->session_counter) < 0) return -ENOMEM; } while (hashmap_contains(m->sessions, id)); @@ -3274,7 +3274,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error do { id = mfree(id); - if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0) + if (asprintf(&id, "%" PRIu64, ++m->inhibit_counter) < 0) return -ENOMEM; } while (hashmap_get(m->inhibitors, id)); diff --git a/src/login/logind.h b/src/login/logind.h index d0b1f9671e..e6a04e0834 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -59,8 +59,8 @@ struct Manager { char **kill_only_users, **kill_exclude_users; bool kill_user_processes; - unsigned long session_counter; - unsigned long inhibit_counter; + uint64_t session_counter; + uint64_t inhibit_counter; Hashmap *session_units; Hashmap *user_units; -- 2.25.1