Skip to content

Use g_child_watch_add instead of waitpid

Submitted by Natanael Copa @ncopa

Assigned to Xfce Bug Triage

Link to original bug (#10046)

Description

Created attachment 5014 0001-Use-g_child_watch_add-instead-of-waitpid.patch

From 0e4d3c7d084d77e9d429e40622619c6dc0f5c2a8 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 10 Apr 2013 20:48:40 +0200
Subject: [PATCH] Use g_child_watch_add instead of waitpid

This reduces code size.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
 xfce4-session/xfsm-compat-kde.c | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/xfce4-session/xfsm-compat-kde.c b/xfce4-session/xfsm-compat-kde.c
index b51387e..ce4b134 100644
--- a/xfce4-session/xfsm-compat-kde.c
+++ b/xfce4-session/xfsm-compat-kde.c
@@ -51,27 +51,11 @@
 static gboolean kde_compat_started = FALSE;
 
 
-static gboolean
-run_timeout (gpointer user_data)
+static void
+run_watcher (GPid pid, gint status, gpointer user_data)
 {
-  int status;
-  int result;
-  pid_t pid = *((pid_t *) user_data);
-
-  result = waitpid (pid, &status, WNOHANG);
-
-  if (result == pid)
-    {
-      gtk_main_quit ();
-    }
-  else if (result == -1)
-    {
-      g_warning ("Failed to wait for process %d: %s",
-                 (int)pid, g_strerror (errno));
-      gtk_main_quit ();
-    }
-
-  return TRUE;
+  g_spawn_close_pid(pid);
+  gtk_main_quit ();
 }
 
 
@@ -98,9 +82,8 @@ run (const gchar *command)
                      G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
                      NULL, NULL, &pid, &error))
     {
-      guint id = g_timeout_add (300, run_timeout, &pid);
+      g_child_watch_add (pid, run_watcher, NULL);
       gtk_main ();
-      g_source_remove (id);
     }
   else
     {
-- 
1.8.2.1

Patch 5014, "0001-Use-g_child_watch_add-instead-of-waitpid.patch":
0001-Use-g_child_watch_add-instead-of-waitpid.patch

Version: Unspecified

Edited by Theo Linkspfeifer