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

Enrico Zini enrico at enricozini.org
Wed Jul 6 09:26:00 UTC 2011


The following commit has been merged in the bug540201 branch:
commit b43f2d04e68fa11b7ec9079c488938591691cb48
Author: Enrico Zini <enrico at enricozini.org>
Date:   Wed Jul 6 11:25:57 2011 +0200

    Prevent killing unstarted processed (marked by (pid_d)-1, ouch)

diff --git a/test-xsession.c b/test-xsession.c
index b96977a..6047183 100644
--- a/test-xsession.c
+++ b/test-xsession.c
@@ -30,34 +30,46 @@ int test_session(struct nodm_xsession_child* s)
     return E_SUCCESS;
 }
 
-int main(int argc, char* argv[])
+void test_trivial_session()
 {
-    test_start("test-xsession", false);
-
     struct nodm_display_manager dm;
     nodm_display_manager_init(&dm);
-
-    // configure display manager for testing
     ensure_succeeds(nodm_display_manager_parse_xcmdline(&dm, "/usr/bin/Xnest :1 -geometry 1x1+0+0"));
     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;
-
-    //nodm_display_manager_dump_status(&dm);
-
     ensure_succeeds(nodm_display_manager_start(&dm));
-
     ensure_succeeds(nodm_display_manager_wait(&dm));
+    ensure_succeeds(nodm_display_manager_stop(&dm));
+    nodm_display_manager_cleanup(&dm);
+}
 
+void test_bad_x_server()
+{
+    struct nodm_display_manager dm;
+    nodm_display_manager_init(&dm);
+    ensure_succeeds(nodm_display_manager_parse_xcmdline(&dm, "/bin/false :1 -geometry 1x1+0+0"));
+    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;
+    ensure_equali(nodm_display_manager_start(&dm), E_X_SERVER_DIED);
     ensure_succeeds(nodm_display_manager_stop(&dm));
+    nodm_display_manager_cleanup(&dm);
+}
+
+int main(int argc, char* argv[])
+{
+    test_start("test-xsession", false);
+
+    test_trivial_session();
+    test_bad_x_server();
 
     // TODO:
     //  - test a wrong xserver command line (dying X server)
     //  - test a wrong username (dying X session)
     //  - start everything fine then kill the X server
 
-    nodm_display_manager_cleanup(&dm);
-
     test_ok();
 }
diff --git a/test.c b/test.c
index 3d70d3f..4662aec 100644
--- a/test.c
+++ b/test.c
@@ -57,6 +57,15 @@ void ensure_equals(const char* a, const char* b)
     }
 }
 
+void ensure_equali(int a, int b)
+{
+    if (a != b)
+    {
+        log_warn("values differ: %d != %d", a, b);
+        test_fail();
+    }
+}
+
 void _ensure_succeeds(int code, const char* file, int line, const char* desc)
 {
     if (code != E_SUCCESS)
diff --git a/test.h b/test.h
index 42e3939..1a5ec60 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 integers are the same
+void ensure_equali(int a, int b);
+
 #define ensure_succeeds(val) _ensure_succeeds((val), __FILE__, __LINE__, #val)
 void _ensure_succeeds(int code, const char* file, int line, const char* desc);
 
diff --git a/xserver.c b/xserver.c
index 19ea745..2a627ba 100644
--- a/xserver.c
+++ b/xserver.c
@@ -226,8 +226,11 @@ cleanup:
 /// Kill the X server
 static int xserver_stop(struct nodm_xserver* srv)
 {
-    kill(srv->pid, SIGTERM);
-    kill(srv->pid, SIGCONT);
+    if (srv->pid > 0)
+    {
+        kill(srv->pid, SIGTERM);
+        kill(srv->pid, SIGCONT);
+    }
     // TODO: wait
     srv->pid = -1;
     unsetenv("DISPLAY");
diff --git a/xsession.c b/xsession.c
index 8a8ccf8..0b2ac35 100644
--- a/xsession.c
+++ b/xsession.c
@@ -127,8 +127,11 @@ int nodm_xsession_start(struct nodm_xsession* s, const struct nodm_xserver* srv)
 
 int nodm_xsession_stop(struct nodm_xsession* s)
 {
-    kill(s->pid, SIGTERM);
-    kill(s->pid, SIGCONT);
+    if (s->pid > 0)
+    {
+        kill(s->pid, SIGTERM);
+        kill(s->pid, SIGCONT);
+    }
     // TODO: wait
     s->pid = -1;
     return E_SUCCESS;

-- 
Automatic Display Manager



More information about the pkg-fso-commits mailing list