summaryrefslogtreecommitdiff
path: root/gnome-settings-daemon
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2008-11-04 08:14:29 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2008-11-04 08:14:29 +0000
commitf0949a64172c3b29a4b406e7fd2422b94c666de8 (patch)
tree3a51b8abd1e77ad8c74ee4617d95e4f46c9af6bf /gnome-settings-daemon
parent015e92a82c6bd19b4d3fcbcbe6ebf950790aba24 (diff)
downloadgnome-settings-daemon-f0949a64172c3b29a4b406e7fd2422b94c666de8.tar.gz
Use a pipe to communicate between child and parent process instead of a
2008-11-04 Behdad Esfahbod <behdad@gnome.org> * gnome-settings-daemon/main.c (daemonize), (main): Use a pipe to communicate between child and parent process instead of a signal. Signals are not queued, so if the child tried to signal the parent before the parent got a chance to wait for it, the signal would be lost and parent wait indefinitely for a signal that would never arrive. svn path=/trunk/; revision=585
Diffstat (limited to 'gnome-settings-daemon')
-rw-r--r--gnome-settings-daemon/main.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/gnome-settings-daemon/main.c b/gnome-settings-daemon/main.c
index 69e5747b..709ba039 100644
--- a/gnome-settings-daemon/main.c
+++ b/gnome-settings-daemon/main.c
@@ -47,6 +47,7 @@
static char *gconf_prefix = NULL;
static gboolean no_daemon = FALSE;
static gboolean debug = FALSE;
+static int pipefds[2];
static GOptionEntry entries[] = {
{"debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
@@ -230,7 +231,10 @@ static gboolean
daemonize (void)
{
int child_pid;
+ char buf[1];
+ signal (SIGPIPE, SIG_IGN);
+ pipe (pipefds);
child_pid = fork ();
switch (child_pid) {
@@ -251,17 +255,16 @@ daemonize (void)
chdir ("/");
umask (0117);
+ close (pipefds[0]);
+
return TRUE;
default:
/* parent */
- /* Wait for child to signal that we are good to go.
- * We actully are just waiting for the child to send
- * us a signal, any signal, not for it to quit. Any
- * signal received from any process gets us out of the
- * wait with EINTR, and that's fine. */
- waitpid (child_pid, NULL, 0);
+ close (pipefds[1]);
+ /* Wait for child to signal that we are good to go. */
+ read (pipefds[0], buf, 1);
exit (EXIT_SUCCESS);
}
@@ -353,7 +356,8 @@ main (int argc, char *argv[])
* process and continue using from the other. So, we just made the
* parent to fork early and wait. */
if (! no_daemon) {
- kill (getppid (), SIGCHLD);
+ write (pipefds[1], "1", 1);
+ close (pipefds[1]);
gnome_settings_profile_end ("daemon initialization");
}