[pkg-fso-commits] [SCM] Automatic Display Manager branch, bug540201, updated. debian/0.6-1-45-ge1626ac

Enrico Zini enrico at enricozini.org
Wed Jul 6 13:37:00 UTC 2011


The following commit has been merged in the bug540201 branch:
commit e1626ac2097015e47c8a73ec6ddce0e58dd51275
Author: Enrico Zini <enrico at enricozini.org>
Date:   Wed Jul 6 15:36:56 2011 +0200

    Moved connection to X server to child initialization code
    
    This prevents the display manager from being exited by xlib after an X I/O error in case the server dies

diff --git a/test-xsession.c b/test-xsession.c
index d0bbb08..9be4dd8 100644
--- a/test-xsession.c
+++ b/test-xsession.c
@@ -30,18 +30,32 @@
 #include <signal.h>
 #include <unistd.h>
 
+static char orig_windowpath[1024];
+
 int test_session(struct nodm_xsession_child* s)
 {
+    int res = nodm_xsession_child_common_env(s);
+    if (res != E_SUCCESS) return res;
+
+    // Check environment
+    ensure_not_equals(orig_windowpath, getenv_with_default("WINDOWPATH", ""));
+
     return E_SUCCESS;
 }
 
 int test_session_bad(struct nodm_xsession_child* s)
 {
+    int res = nodm_xsession_child_common_env(s);
+    if (res != E_SUCCESS) return res;
+
     return E_USAGE;
 }
 
 int test_session_x_killer(struct nodm_xsession_child* s)
 {
+    int res = nodm_xsession_child_common_env(s);
+    if (res != E_SUCCESS) return res;
+
     if (s->srv->pid == -1)
     {
         fprintf(stderr, "server PID has not been set\n");
@@ -140,6 +154,9 @@ int main(int argc, char* argv[])
 {
     test_start("test-xsession", true);
 
+    // Save original window path to check if it changed in the X session
+    (void)bounded_strcpy(orig_windowpath, getenv_with_default("WINDOWPATH", ""));
+
     test_trivial_session();
     test_bad_x_server();
     test_failing_x_session();
diff --git a/test.c b/test.c
index 4662aec..bc9b0bd 100644
--- a/test.c
+++ b/test.c
@@ -37,7 +37,7 @@ void test_start(const char* testname, bool verbose)
 void test_fail()
 {
     log_end();
-    exit(1);
+    exit(E_PROGRAMMING);
 }
 
 void test_ok()
@@ -57,6 +57,20 @@ void ensure_equals(const char* a, const char* b)
     }
 }
 
+void ensure_not_equals(const char* a, const char* b)
+{
+    if (a == NULL && b == NULL)
+    {
+        log_warn("strings are both NULL");
+        test_fail();
+    }
+    if (a != NULL && b != NULL && strcmp(a, b) == 0)
+    {
+        log_warn("strings are both \"%s\"", a);
+        test_fail();
+    }
+}
+
 void ensure_equali(int a, int b)
 {
     if (a != b)
diff --git a/test.h b/test.h
index 1a5ec60..c8cd66c 100644
--- a/test.h
+++ b/test.h
@@ -37,6 +37,9 @@ void test_ok() __attribute__((noreturn));
 /// Ensure that two strings are the same
 void ensure_equals(const char* a, const char* b);
 
+/// Ensure that two strings are different
+void ensure_not_equals(const char* a, const char* b);
+
 /// Ensure that two integers are the same
 void ensure_equali(int a, int b);
 
diff --git a/xserver.c b/xserver.c
index f3d5c28..fed91bb 100644
--- a/xserver.c
+++ b/xserver.c
@@ -79,19 +79,7 @@ void nodm_xserver_init(struct nodm_xserver* srv)
     srv->windowpath = NULL;
 }
 
-/**
- * Start the X server and wait until it's ready to accept connections.
- *
- * @param srv
- *   The struct nodm_xserver with X server information. argv and name are expected to
- *   be filled, pid is filled.
- * @param timeout_sec
- *   Timeout in seconds after which if the X server is not ready, we give up
- *   and return an error.
- * @return
- *   Exit status as described by the E_* constants
- */
-static int xserver_start(struct nodm_xserver* srv, unsigned timeout_sec)
+int nodm_xserver_start(struct nodm_xserver* srv)
 {
     // Function return code
     int return_code = E_SUCCESS;
@@ -155,7 +143,7 @@ static int xserver_start(struct nodm_xserver* srv, unsigned timeout_sec)
     }
 
     // Wait for SIGUSR1, for the server to die or for a timeout
-    struct timespec timeout = { .tv_sec = timeout_sec, .tv_nsec = 0 };
+    struct timespec timeout = { .tv_sec = srv->conf_timeout, .tv_nsec = 0 };
     while (!server_started)
     {
         // Check if the server has died
@@ -195,7 +183,7 @@ static int xserver_start(struct nodm_xserver* srv, unsigned timeout_sec)
             return_code = E_OS_ERROR;
             goto cleanup;
         } else {
-            log_err("X server did not respond after %u seconds", timeout_sec);
+            log_err("X server did not respond after %u seconds", srv->conf_timeout);
             return_code = E_X_SERVER_TIMEOUT;
             goto cleanup;
         }
@@ -215,8 +203,7 @@ cleanup:
     return return_code;
 }
 
-/// Kill the X server
-static int xserver_stop(struct nodm_xserver* srv)
+int nodm_xserver_stop(struct nodm_xserver* srv)
 {
     if (srv->pid > 0)
     {
@@ -249,15 +236,7 @@ static int x_error_handler(Display* dpy, XErrorEvent* e)
 }
 */
 
-/**
- * Connect to the X server
- *
- * Uses srv->name, sets srv->dpy.
- *
- * @return
- *   Exit status as described by the E_* constants
- */
-static int xserver_connect(struct nodm_xserver* srv)
+int nodm_xserver_connect(struct nodm_xserver* srv)
 {
     //XSetErrorHandler(x_error_handler);
 
@@ -274,31 +253,18 @@ static int xserver_connect(struct nodm_xserver* srv)
     return srv->dpy == NULL ? E_X_SERVER_CONNECT : E_SUCCESS;
 }
 
-/**
- * Close connection to the X server
- *
- * Uses srv->dpy, sets it to NULL.
- *
- * @return
- *   Exit status as described by the E_* constants
- */
-static int xserver_disconnect(struct nodm_xserver* srv)
+int nodm_xserver_disconnect(struct nodm_xserver* srv)
 {
     // TODO: get/check pending errors (how?)
-    XCloseDisplay(srv->dpy);
-    srv->dpy = NULL;
+    if (srv->dpy != NULL)
+    {
+        XCloseDisplay(srv->dpy);
+        srv->dpy = NULL;
+    }
     return E_SUCCESS;
 }
 
-/**
- * Get the WINDOWPATH value for the server
- *
- * Uses srv->dpy, sets srv->windowpath
- *
- * @return
- *   Exit status as described by the E_* constants
- */
-static int xserver_read_window_path(struct nodm_xserver* srv)
+int nodm_xserver_read_window_path(struct nodm_xserver* srv)
 {
     /* setting WINDOWPATH for clients */
     Atom prop;
@@ -372,41 +338,6 @@ static int xserver_read_window_path(struct nodm_xserver* srv)
     return E_SUCCESS;
 }
 
-int nodm_xserver_start(struct nodm_xserver* srv)
-{
-    int return_code = E_SUCCESS;
-
-    return_code = xserver_start(srv, srv->conf_timeout);
-    if (return_code != E_SUCCESS)
-        goto cleanup;
-
-    return_code = xserver_connect(srv);
-    if (return_code != E_SUCCESS)
-        goto cleanup;
-
-    return_code = xserver_read_window_path(srv);
-    if (return_code != E_SUCCESS)
-        goto cleanup;
-
-cleanup:
-    if (return_code != E_SUCCESS)
-        nodm_xserver_stop(srv);
-    return return_code;
-}
-
-int nodm_xserver_stop(struct nodm_xserver* srv)
-{
-    int res1 = E_SUCCESS, res2 = E_SUCCESS;
-
-    if (srv->dpy != NULL)
-        res1 = xserver_disconnect(srv);
-    if (srv->pid != -1)
-        res2 = xserver_stop(srv);
-
-    if (res1 != E_SUCCESS) return res1;
-    return res2;
-}
-
 void nodm_xserver_dump_status(struct nodm_xserver* srv)
 {
     fprintf(stderr, "xserver start timeout: %d\n", srv->conf_timeout);
diff --git a/xserver.h b/xserver.h
index 70162ca..6c701a8 100644
--- a/xserver.h
+++ b/xserver.h
@@ -47,7 +47,15 @@ struct nodm_xserver
  */
 void nodm_xserver_init(struct nodm_xserver* srv);
 
-/// Start the X server
+/**
+ * Start the X server and wait until it is ready to accept connections.
+ *
+ * @param srv
+ *   The struct nodm_xserver with X server information. argv and name are expected to
+ *   be filled, pid is filled.
+ * @return
+ *   Exit status as described by the E_* constants
+ */
 int nodm_xserver_start(struct nodm_xserver* srv);
 
 /// Stop the X server
@@ -56,4 +64,34 @@ int nodm_xserver_stop(struct nodm_xserver* srv);
 /// Dump all internal status to stderr
 void nodm_xserver_dump_status(struct nodm_xserver* srv);
 
+/**
+ * Connect to the X server
+ *
+ * Uses srv->name, sets srv->dpy.
+ *
+ * @return
+ *   Exit status as described by the E_* constants
+ */
+int nodm_xserver_connect(struct nodm_xserver* srv);
+
+/**
+ * Close connection to the X server
+ *
+ * Uses srv->dpy, sets it to NULL.
+ *
+ * @return
+ *   Exit status as described by the E_* constants
+ */
+int nodm_xserver_disconnect(struct nodm_xserver* srv);
+
+/**
+ * Get the WINDOWPATH value for the server
+ *
+ * Uses srv->dpy, sets srv->windowpath
+ *
+ * @return
+ *   Exit status as described by the E_* constants
+ */
+int nodm_xserver_read_window_path(struct nodm_xserver* srv);
+
 #endif
diff --git a/xsession-child.c b/xsession-child.c
index b472e43..18a6e23 100644
--- a/xsession-child.c
+++ b/xsession-child.c
@@ -300,6 +300,16 @@ static void shutdown_pam(struct nodm_xsession_child* s)
 
 int nodm_xsession_child_common_env(struct nodm_xsession_child* s)
 {
+    int return_code = E_SUCCESS;
+
+    // Read the WINDOWPATH value from the X server
+    return_code = nodm_xserver_connect(s->srv);
+    if (return_code != E_SUCCESS) goto cleanup;
+    return_code = nodm_xserver_read_window_path(s->srv);
+    if (return_code != E_SUCCESS) goto cleanup;
+    return_code = nodm_xserver_disconnect(s->srv);
+    if (return_code != E_SUCCESS) goto cleanup;
+
     // Setup environment
     setenv("HOME", s->pwent.pw_dir, 1);
     setenv("USER", s->pwent.pw_name, 1);
@@ -327,7 +337,10 @@ int nodm_xsession_child_common_env(struct nodm_xsession_child* s)
             cleanup_xse(0, s->pwent.pw_dir);
     }
 
-    return E_SUCCESS;
+cleanup:
+    if (s->srv->dpy != NULL)
+        nodm_xserver_disconnect(s->srv);
+    return return_code;
 }
 
 int nodm_xsession_child(struct nodm_xsession_child* s)
diff --git a/xsession-child.h b/xsession-child.h
index 82214d6..2a232af 100644
--- a/xsession-child.h
+++ b/xsession-child.h
@@ -30,7 +30,7 @@ struct nodm_xserver;
 struct nodm_xsession_child
 {
     /// X server we connect to
-    const struct nodm_xserver* srv;
+    struct nodm_xserver* srv;
 
     /// If set to true, perform ~/.xsession-errors cleanup
     bool conf_cleanup_xse;
diff --git a/xsession.c b/xsession.c
index 0b2ac35..0144be2 100644
--- a/xsession.c
+++ b/xsession.c
@@ -51,7 +51,7 @@ int nodm_xsession_init(struct nodm_xsession* s)
     return E_SUCCESS;
 }
 
-int nodm_xsession_start(struct nodm_xsession* s, const struct nodm_xserver* srv)
+int nodm_xsession_start(struct nodm_xsession* s, struct nodm_xserver* srv)
 {
     struct nodm_xsession_child child;
     child.srv = srv;
diff --git a/xsession.h b/xsession.h
index 4950795..f5ce321 100644
--- a/xsession.h
+++ b/xsession.h
@@ -57,7 +57,7 @@ struct nodm_xsession
 int nodm_xsession_init(struct nodm_xsession* s);
 
 /// Start the X session
-int nodm_xsession_start(struct nodm_xsession* s, const struct nodm_xserver* srv);
+int nodm_xsession_start(struct nodm_xsession* s, struct nodm_xserver* srv);
 
 /// Stop the X session
 int nodm_xsession_stop(struct nodm_xsession* s);

-- 
Automatic Display Manager



More information about the pkg-fso-commits mailing list