hal/hald hald.c,1.13,1.14

David Zeuthen david at freedesktop.org
Mon Aug 23 10:59:57 PDT 2004


Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv14395/hald

Modified Files:
	hald.c 
Log Message:
2004-08-23  David Zeuthen  <david at fubar.dk>

	* hald/hald.c (main): Setup a pipe and make parent wait until client
	writes to it.
	(osspec_probe_done): Write to the parent to make it exit



Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- hald.c	23 Aug 2004 17:19:01 -0000	1.13
+++ hald.c	23 Aug 2004 17:59:50 -0000	1.14
@@ -236,6 +236,8 @@
 /** This is set to #TRUE if we are shutting down and #FALSE otherwise */
 dbus_bool_t hald_is_shutting_down;
 
+static int startup_daemonize_pipe[2];
+
 /** Entry point for HAL daemon
  *
  *  @param  argc                Number of arguments
@@ -248,6 +250,8 @@
 	GMainLoop *loop;
 	guint sigterm_iochn_listener_source_id;
 
+	g_type_init ();
+
 	logger_init ();
 	if (getenv ("HALD_VERBOSE"))
 		hald_is_verbose = TRUE;
@@ -318,6 +322,12 @@
 
 		HAL_INFO (("Becoming a daemon"));
 
+		if (pipe (startup_daemonize_pipe) != 0) {
+			fprintf (stderr, "Could not setup pipe: %s\n", strerror(errno));
+			exit (1);
+		}
+
+
 		if (chdir ("/") < 0) {
 			fprintf (stderr, "Could not chdir to /: %s\n", strerror(errno));
 			exit (1);
@@ -345,9 +355,13 @@
 			break;
 
 		default:
-			/* parent */
-			exit (0);
-			break;
+		        {
+				char buf[1];
+				/* parent, block until child writes */
+				read (startup_daemonize_pipe[0], &buf, sizeof (buf));
+				exit (0);
+				break;
+			}
 		}
 
 		/* Create session */
@@ -380,8 +394,6 @@
 
 	hald_read_conf_file ();
 
-	g_type_init ();
-
 	/* set up the dbus services */
 	if (!hald_dbus_init ())
 		return 1;
@@ -409,9 +421,15 @@
 void 
 osspec_probe_done (void)
 {
+	char buf[1] = {0};
 
 	HAL_INFO (("Device probing completed"));
 
+	/* tell parent to exit */
+	write (startup_daemonize_pipe[1], buf, sizeof (buf));
+	close (startup_daemonize_pipe[0]);
+	close (startup_daemonize_pipe[1]);
+
 	hald_is_initialising = FALSE;
 }
 




More information about the hal-commit mailing list