hal/hald hald.c,1.17,1.18 haldaemon.in,1.2,1.3

David Zeuthen david at freedesktop.org
Thu Sep 16 15:23:12 PDT 2004


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

Modified Files:
	hald.c haldaemon.in 
Log Message:
2004-09-17  David Zeuthen  <david at fubar.dk>

	Patch from Steve Grubb <linux_4ever at yahoo.com>.

	* configure.in: Add HALD_PID_FILE to config.h

	* hald/hald.c:
	(delete_pid): New function
	(main): Write pidfile. Set atexit to delete_pid.

	* hald/haldaemon.in: Don't write pidfile



Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- hald.c	3 Sep 2004 18:28:56 -0000	1.17
+++ hald.c	16 Sep 2004 22:23:10 -0000	1.18
@@ -55,6 +55,10 @@
 #include "hald_dbus.h"
 #include "hald_conf.h"
 
+static void delete_pid(void) {
+    unlink(HALD_PID_FILE);
+}
+
 /**
  * @defgroup HalDaemon HAL daemon
  * @brief The HAL daemon manages persistent device objects available through
@@ -392,6 +396,8 @@
 	if (opt_become_daemon) {
 		int child_pid;
 		int dev_null_fd;
+		int pf;
+		char pid[9];
 
 		HAL_INFO (("Becoming a daemon"));
 
@@ -417,7 +423,7 @@
 
 			dev_null_fd = open ("/dev/null", O_RDWR);
 			/* ignore if we can't open /dev/null */
-			if (dev_null_fd > 0) {
+			if (dev_null_fd >= 0) {
 				/* attach /dev/null to stdout, stdin, stderr */
 				dup2 (dev_null_fd, 0);
 				dup2 (dev_null_fd, 1);
@@ -429,9 +435,9 @@
 
 		default:
 		        {
-				char buf[1];
 				/* parent, block until child writes */
-				/*read (startup_daemonize_pipe[0], &buf, sizeof (buf));*/
+				/* char buf[1];
+				read (startup_daemonize_pipe[0], &buf, sizeof (buf));*/
 				exit (0);
 				break;
 			}
@@ -439,6 +445,20 @@
 
 		/* Create session */
 		setsid ();
+
+		/* remove old pid file */
+		unlink(HALD_PID_FILE);
+
+		/* Make a new one */
+		if ((pf=open(HALD_PID_FILE, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL,
+			0644)) == -1) {
+			HAL_ERROR (("Cannot create pid file"));
+			exit(1);
+		}
+		sprintf(pid, "%lu\n", (long unsigned)getpid());
+		write(pf, pid, strlen(pid));
+		close(pf);
+		atexit(delete_pid);
 	}
 
 

Index: haldaemon.in
===================================================================
RCS file: /cvs/hal/hal/hald/haldaemon.in,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- haldaemon.in	23 Aug 2004 19:57:06 -0000	1.2
+++ haldaemon.in	16 Sep 2004 22:23:10 -0000	1.3
@@ -28,7 +28,7 @@
     daemon --check $servicename $processname
     RETVAL=$?
     echo
-    [ $RETVAL -eq 0 ] && touch @LOCALSTATEDIR@/lock/subsys/$servicename && echo `/sbin/pidof $processname` > @HALD_PID_FILE@
+    [ $RETVAL -eq 0 ] && touch @LOCALSTATEDIR@/lock/subsys/$servicename
 }
 
 stop() {




More information about the hal-commit mailing list