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

Enrico Zini enrico at enricozini.org
Tue Jul 5 23:47:16 UTC 2011


The following commit has been merged in the bug540201 branch:
commit a20ec82faf522d0032d6a5975158c5ba15ee6aae
Author: Enrico Zini <enrico at enricozini.org>
Date:   Wed Jul 6 01:46:38 2011 +0200

    Display manager start/stop/wait functions

diff --git a/dm.c b/dm.c
index 1f84cde..e2482f0 100644
--- a/dm.c
+++ b/dm.c
@@ -20,9 +20,14 @@
 
 #include "dm.h"
 #include "common.h"
+#include "log.h"
 #include <wordexp.h>
 #include <stdlib.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+
 
 void nodm_display_manager_init(struct nodm_display_manager* dm)
 {
@@ -43,6 +48,59 @@ void nodm_display_manager_cleanup(struct nodm_display_manager* dm)
     }
 }
 
+int nodm_display_manager_start(struct nodm_display_manager* dm)
+{
+    int res = nodm_xserver_start(&dm->srv);
+    if (res != E_SUCCESS) return res;
+
+    res = nodm_xsession_start(&dm->session, &dm->srv);
+    if (res != E_SUCCESS) return res;
+
+    return E_SUCCESS;
+}
+
+int nodm_display_manager_stop(struct nodm_display_manager* dm)
+{
+    int res = nodm_xsession_stop(&dm->session);
+    if (res != E_SUCCESS) return res;
+
+    res = nodm_xserver_stop(&dm->srv);
+    if (res != E_SUCCESS) return res;
+
+    return E_SUCCESS;
+}
+
+int nodm_display_manager_wait(struct nodm_display_manager* dm)
+{
+    while (true)
+    {
+        // Wait for one child to exit
+        int status;
+        pid_t child = waitpid(-1, &status, 0);
+        if (child == -1)
+        {
+            if (errno == EINTR)
+                continue;
+            else
+            {
+                log_warn("waitpid error: %m");
+                return E_OS_ERROR;
+            }
+        }
+
+        if (child == dm->srv.pid)
+        {
+            // Server died
+            log_warn("X server died with status %d", status);
+            return E_X_SERVER_DIED;
+        } else if (child == dm->session.pid) {
+            // Session died
+            log_warn("X session died with status %d", status);
+            return status;
+        }
+    }
+}
+
 int nodm_display_manager_parse_xcmdline(struct nodm_display_manager* s, const char* xcmdline)
 {
     int return_code = E_SUCCESS;
diff --git a/dm.h b/dm.h
index 5d4571b..593e395 100644
--- a/dm.h
+++ b/dm.h
@@ -43,6 +43,15 @@ void nodm_display_manager_init(struct nodm_display_manager* dm);
 /// Cleanup at the end of the display manager
 void nodm_display_manager_cleanup(struct nodm_display_manager* dm);
 
+/// Start X and the X session
+int nodm_display_manager_start(struct nodm_display_manager* dm);
+
+/// Wait for X or the X session to end
+int nodm_display_manager_wait(struct nodm_display_manager* dm);
+
+/// Stop X and the X session
+int nodm_display_manager_stop(struct nodm_display_manager* dm);
+
 /**
  * Split xcmdline using wordexp shell-like expansion and set dm->srv.argv.
  *
diff --git a/test-xsession.c b/test-xsession.c
index 7321d3f..fff7e34 100644
--- a/test-xsession.c
+++ b/test-xsession.c
@@ -20,10 +20,15 @@
 
 #include "log.h"
 #include "common.h"
-#include "xsession.h"
+#include "dm.h"
 #include <stdio.h>
 #include <stdlib.h>
 
+int test_session(struct nodm_xsession_child* s)
+{
+    return E_SUCCESS;
+}
+
 int main(int argc, char* argv[])
 {
     struct log_config cfg = {
@@ -38,17 +43,45 @@ int main(int argc, char* argv[])
     setenv("NODM_SESSION", "/bin/true", 1);
     setenv("NODM_USER", getenv_with_default("USER", "root"), 1);
 
-    struct nodm_xsession s;
-    nodm_xsession_init(&s);
+    int res;
+
+    struct nodm_display_manager dm;
+    nodm_display_manager_init(&dm);
+
+    // configure display manager for testing
+    res = nodm_display_manager_parse_xcmdline(&dm, "/usr/bin/Xnest :1 -geometry 1x1+0+0");
+    if (res != E_SUCCESS)
+    {
+        fprintf(stderr, "nodm_display_manager_parse_xcmdline return code: %d\n", res);
+        goto cleanup;
+    }
+    dm.session.conf_use_pam = false;
+    dm.session.conf_cleanup_xse = false;
+    dm.session.conf_run_as[0] = 0;
+    dm.session.child_body = test_session;
+
+    res = nodm_display_manager_start(&dm);
+    if (res != E_SUCCESS)
+    {
+        fprintf(stderr, "nodm_display_manager_start return code: %d\n", res);
+        goto cleanup;
+    }
 
-    int res = E_SUCCESS;
+    res = nodm_display_manager_wait(&dm);
+    if (res != E_SUCCESS)
+    {
+        fprintf(stderr, "nodm_display_manager_wait return code: %d\n", res);
+        goto cleanup;
+    }
 
-    //res = nodm_session_parse_cmdline(&s, xcmdline);
-    //if (res != E_SUCCESS) goto cleanup;
+    res = nodm_display_manager_stop(&dm);
+    if (res != E_SUCCESS)
+    {
+        fprintf(stderr, "nodm_display_manager_stop return code: %d\n", res);
+        goto cleanup;
+    }
 
-    //res = nodm_x_with_session(&s);
-    //fprintf(stderr, "nodm_x_with_session_cmdline returned %d\n", res);
-    if (res != E_SUCCESS) goto cleanup;
+    nodm_display_manager_cleanup(&dm);
 
 cleanup:
     log_end();
diff --git a/test-xstart.c b/test-xstart.c
index 0d5d213..4e4860f 100644
--- a/test-xstart.c
+++ b/test-xstart.c
@@ -44,16 +44,16 @@ int main(int argc, char* argv[])
     if (res != E_SUCCESS)
     {
         fprintf(stderr, "nodm_xserver_start return code: %d\n", res);
-        return 1;
+        return res;
     }
 
     res = nodm_xserver_stop(&srv);
     if (res != E_SUCCESS)
     {
         fprintf(stderr, "nodm_xserver_stop return code: %d\n", res);
-        return 4;
+        return res;
     }
 
     log_end();
-    return 0;
+    return E_SUCCESS;
 }
diff --git a/xsession-child.h b/xsession-child.h
index 2a232af..82214d6 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
-    struct nodm_xserver* srv;
+    const 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 ff5793a..4c5feea 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, struct nodm_xserver* srv)
+int nodm_xsession_start(struct nodm_xsession* s, const struct nodm_xserver* srv)
 {
     struct nodm_xsession_child child;
     child.srv = srv;
diff --git a/xsession.h b/xsession.h
index 759c56b..a39dd54 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, struct nodm_xserver* srv);
+int nodm_xsession_start(struct nodm_xsession* s, const 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