! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Use g_child_watch_add instead of waitpid
Status:
RESOLVED: MOVED
Severity:
enhancement
Product:
Xfce4-session
Component:
General

Comments

Description Natanael Copa 2013-04-29 13:44:40 CEST
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
Comment 1 Nick Schermer editbugs 2013-04-29 17:04:52 CEST
This makes the code run differently. The timeout is also required to test if nothing is returned. So a proper solution would be a combination of both the child watch (for waitpid result) and a timeout (say at 500ms) for a failed child_watch.
Comment 2 Git Bot editbugs 2020-05-26 00:43:29 CEST
-- GitLab Migration Automatic Message --

This bug has been migrated to xfce.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.xfce.org/xfce/xfce4-session/-/issues/14.

Please create an account or use an existing account on one of our supported OAuth providers. 

If you want to fork to submit patches and merge requests please continue reading here: https://docs.xfce.org/contribute/dev/git/start#gitlab_forks_and_merge_requests

Also feel free to reach out to us on the mailing list https://mail.xfce.org/mailman/listinfo/xfce4-dev

Bug #10046

Reported by:
Natanael Copa
Reported on: 2013-04-29
Last modified on: 2020-05-26

People

Assignee:
Xfce Bug Triage
CC List:
2 users

Version

Version:
Unspecified

Attachments

Additional information