]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Ignore stale X server locks
authorRobert Ancell <robert.ancell@canonical.com>
Tue, 16 Apr 2013 01:03:09 +0000 (13:03 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Tue, 16 Apr 2013 01:03:09 +0000 (13:03 +1200)
src/xserver-local.c

index 21a8ae20ec55e1aa3c36f44020bb09216d6f37f9..5fd35a380ced462372de267369dc19f80565bd5f 100644 (file)
@@ -77,8 +77,11 @@ display_number_in_use (guint display_number)
 {
     GList *link;
     gchar *path;
-    gboolean result;
+    gboolean exists;
+    gboolean stale = TRUE;
+    gchar *data;
 
+    /* See if we know we are managing a server with that number */
     for (link = display_numbers; link; link = link->next)
     {
         guint number = GPOINTER_TO_UINT (link->data);
@@ -86,11 +89,28 @@ display_number_in_use (guint display_number)
             return TRUE;
     }
 
+    /* See if an X server that we don't know of has a lock on that number */
     path = g_strdup_printf ("/tmp/.X%d-lock", display_number);
-    result = g_file_test (path, G_FILE_TEST_EXISTS);
+    exists = g_file_test (path, G_FILE_TEST_EXISTS);
     g_free (path);
+    if (!exists)
+        return FALSE;
 
-    return result;
+    /* See if that lock file is valid, ignore it if the contents are invalid or the process doesn't exist */
+    if (g_file_get_contents (path, &data, NULL, NULL))
+    {
+        int pid;
+
+        pid = atoi (g_strstrip (data));
+        if (pid <= 0)
+            return FALSE;
+
+        errno = 0;
+        if (kill (pid, 0) < 0 && errno == ESRCH)
+            return FALSE;
+    }
+  
+    return TRUE;
 }
 
 guint