]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Tidy up blocking process code
authorRobert Ancell <robert.ancell@canonical.com>
Fri, 16 Sep 2011 04:33:32 +0000 (14:33 +1000)
committerRobert Ancell <robert.ancell@canonical.com>
Fri, 16 Sep 2011 04:33:32 +0000 (14:33 +1000)
src/display.c
src/process.c
src/process.h
src/seat.c

index b869d2318998f16dcb5fcecb84a7e7d863c4af78..fc7dc14e1ae6f5b8ced933a5692b224b925d85e1 100644 (file)
@@ -226,19 +226,6 @@ get_guest_username (Display *display)
     return username;
 }
 
-static void
-session_exited_cb (Session *session, gint status, Display *display)
-{
-    if (status != 0)
-        g_debug ("Session exited with value %d", status);
-}
-
-static void
-session_terminated_cb (Session *session, gint signum, Display *display)
-{
-    g_debug ("Session terminated with signal %d", signum);
-}
-
 static void
 check_stopped (Display *display)
 {
@@ -457,8 +444,6 @@ create_session (Display *display, PAMSession *authentication, const gchar *sessi
     g_signal_emit (display, signals[CREATE_SESSION], 0, &session);
     g_return_val_if_fail (session != NULL, NULL);
 
-    g_signal_connect (session, "exited", G_CALLBACK (session_exited_cb), display);
-    g_signal_connect (session, "terminated", G_CALLBACK (session_terminated_cb), display);
     if (is_greeter)
         g_signal_connect_after (session, "stopped", G_CALLBACK (greeter_session_stopped_cb), display);
     else
index e4e931476db7e6a60d1cdee7323d85667859e740..c47ef14a99310b24acbfc792a034da022e75f000 100644 (file)
@@ -26,8 +26,6 @@ enum {
     STARTED,
     GOT_DATA,
     GOT_SIGNAL,  
-    EXITED,
-    TERMINATED,
     STOPPED,
     LAST_SIGNAL
 };
@@ -52,6 +50,9 @@ struct ProcessPrivate
  
     /* Process ID */
     GPid pid;
+  
+    /* Exit status of process */
+    int exit_status;
 
     /* Timeout waiting for process to quit */
     guint quit_timeout;
@@ -165,16 +166,12 @@ process_watch_cb (GPid pid, gint status, gpointer data)
 {
     Process *process = data;
 
+    process->priv->exit_status = status;
+
     if (WIFEXITED (status))
-    {
         g_debug ("Process %d exited with return value %d", pid, WEXITSTATUS (status));
-        g_signal_emit (process, signals[EXITED], 0, WEXITSTATUS (status));
-    }
     else if (WIFSIGNALED (status))
-    {
         g_debug ("Process %d terminated with signal %d", pid, WTERMSIG (status));
-        g_signal_emit (process, signals[TERMINATED], 0, WTERMSIG (status));
-    }
 
     if (process->priv->quit_timeout)
         g_source_remove (process->priv->quit_timeout);
@@ -359,11 +356,27 @@ quit_timeout_cb (Process *process)
 void
 process_stop (Process *process)
 {
+    g_return_if_fail (process != NULL);
+
     /* Send SIGTERM, and then SIGKILL if no response */
     process->priv->quit_timeout = g_timeout_add (5000, (GSourceFunc) quit_timeout_cb, process);
     process_signal (process, SIGTERM);
 }
 
+void
+process_wait (Process *process)
+{
+    g_return_if_fail (process != NULL);
+    waitpid (process->priv->pid, NULL, 0);
+}
+
+int
+process_get_exit_status (Process *process)
+{
+    g_return_val_if_fail (process != NULL, -1);
+    return process->priv->exit_status;
+}
+
 static void
 process_init (Process *process)
 {
@@ -478,22 +491,6 @@ process_class_init (ProcessClass *klass)
                       NULL, NULL,
                       g_cclosure_marshal_VOID__INT,
                       G_TYPE_NONE, 1, G_TYPE_INT);
-    signals[EXITED] =
-        g_signal_new ("exited",
-                      G_TYPE_FROM_CLASS (klass),
-                      G_SIGNAL_RUN_LAST,
-                      G_STRUCT_OFFSET (ProcessClass, exited),
-                      NULL, NULL,
-                      g_cclosure_marshal_VOID__INT,
-                      G_TYPE_NONE, 1, G_TYPE_INT);
-    signals[TERMINATED] =
-        g_signal_new ("terminated",
-                      G_TYPE_FROM_CLASS (klass),
-                      G_SIGNAL_RUN_LAST,
-                      G_STRUCT_OFFSET (ProcessClass, terminated),
-                      NULL, NULL,
-                      g_cclosure_marshal_VOID__INT,
-                      G_TYPE_NONE, 1, G_TYPE_INT);
     signals[STOPPED] =
         g_signal_new ("stopped",
                       G_TYPE_FROM_CLASS (klass),
index 826c5bbad778013e7d2ad6c951f7fdd662af7de7..e9e7bb328f4a236e55c685aa68c72aabedd17629 100644 (file)
@@ -38,8 +38,6 @@ typedef struct
     void (*started)(Process *process);
     void (*got_data)(Process *process);
     void (*got_signal)(Process *process, int signum);
-    void (*exited)(Process *process, int status);
-    void (*terminated)(Process *process, int signum);
     void (*stopped)(Process *process);
 } ProcessClass;
 
@@ -79,6 +77,10 @@ void process_signal (Process *process, int signum);
 
 void process_stop (Process *process);
 
+void process_wait (Process *process);
+
+int process_get_exit_status (Process *process);
+
 G_END_DECLS
 
 #endif /* _PROCESS_H_ */
index 9b8bc441780a352f05349ce327ec9abd126e2a57..279d6dac30f9cdd4557e6cdf85d221c12605b56a 100644 (file)
@@ -237,7 +237,6 @@ static gboolean
 run_script (Seat *seat, Display *display, const gchar *script_name, User *user)
 {
     Process *process;
-    int exit_status;
     gboolean result = FALSE;
 
     process = process_new ();
@@ -258,8 +257,11 @@ run_script (Seat *seat, Display *display, const gchar *script_name, User *user)
 
     if (process_start (process))
     {
-        waitpid (process_get_pid (process), &exit_status, 0);
+        int exit_status;
 
+        process_wait (process);
+
+        exit_status = process_get_exit_status (process);
         if (WIFEXITED (exit_status))
         {
             g_debug ("Exit status of %s: %d", script_name, WEXITSTATUS (exit_status));