chiark / gitweb /
logind: when generating session ids with a counter, retry if session is already allocated
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Jun 2011 18:46:22 +0000 (20:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 24 Jun 2011 18:46:22 +0000 (20:46 +0200)
src/logind-dbus.c
src/logind.h

index 0f3de41fff2ab1046c16a0580f21f17f0ea2ec01..2bad549fc528a60e49eda77ec1027cfda8d4e32e 100644 (file)
@@ -176,7 +176,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
         Seat *s;
         DBusMessageIter iter;
         int r;
-        char *id, *p;
+        char *id = NULL, *p;
         int vtnr = -1;
         int pipe_fds[2] = { -1, -1 };
         DBusMessage *reply = NULL;
@@ -306,19 +306,30 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
 
         audit_session_from_pid(leader, &audit_id);
 
-        if (audit_id > 0)
+        if (audit_id > 0) {
                 asprintf(&id, "%lu", (unsigned long) audit_id);
-        else
-                asprintf(&id, "c%lu", ++m->session_counter);
 
-        if (!id) {
-                r = -ENOMEM;
-                goto fail;
-        }
+                if (!id) {
+                        r = -ENOMEM;
+                        goto fail;
+                }
 
-        if (hashmap_get(m->sessions, id)) {
-                r = -EEXIST;
-                goto fail;
+                if (hashmap_get(m->sessions, id)) {
+                        r = -EEXIST;
+                        goto fail;
+                }
+
+        } else {
+                do {
+                        free(id);
+                        asprintf(&id, "c%lu", ++m->session_counter);
+
+                        if (!id) {
+                                r = -ENOMEM;
+                                goto fail;
+                        }
+
+                } while (hashmap_get(m->sessions, id));
         }
 
         r = manager_add_session(m, user, id, &session);
index d8674e75116a5fed8d77bba1e9c06eb8f678bb30..2b9b702f3d9591d3154ab936e2232525b2fb9acc 100644 (file)
@@ -40,6 +40,7 @@
  * subscribe to fd HUP
  * D-Bus method: AttachDevice(seat, device);
  * D-Bus method: PermitLinger(user, bool b);
+ * properly handle if two sessions with the same loginuid are attempted to be created
  *
  * non-local X11 server
  * reboot/shutdown halt management