[BusyBox] writing pidfiles

Stephane Billiart stephane.billiart at gmail.com
Tue Aug 23 02:16:16 MDT 2005


Attached is a patch I use on my installation to have crond and syslogd
write out a pidfile like their GNU counterparts (it makes monitoring
easier).
Looking through the sources, I also noticed that other applets write
pidfiles (fakeidentd, inetd, udhcpd) so it might save a few bytes to
make a libbb function for this but I did not go that far yet.

Any interest in making this part of the official version or is this
useless bloat?

-- 
Stéphane Billiart                      http://perso.wanadoo.fr/billiart/
-------------- next part --------------
diff -ruN busybox-1.00/miscutils/crond.c busybox-1.00.new/miscutils/crond.c
--- busybox-1.00/miscutils/crond.c	2004-04-14 19:51:21.000000000 +0200
+++ busybox-1.00.new/miscutils/crond.c	2005-05-25 07:00:32.000000000 +0200
@@ -237,6 +237,12 @@
 		long dt;
 		short rescan = 60;
 		short sleep_time = 60;
+		FILE *pidf;
+
+		if ((pidf = fopen("/var/run/crond.pid", "w")) != NULL) {
+			fprintf(pidf, "%d\n", getpid());
+			fclose(pidf);
+		}
 
 		for (;;) {
 			sleep((sleep_time + 1) - (short) (time(NULL) % sleep_time));
diff -ruN busybox-1.00/sysklogd/syslogd.c busybox-1.00.new/sysklogd/syslogd.c
--- busybox-1.00/sysklogd/syslogd.c	2004-09-14 20:12:13.000000000 +0200
+++ busybox-1.00.new/sysklogd/syslogd.c	2005-05-25 07:08:32.000000000 +0200
@@ -691,12 +691,18 @@
 	umask(0);
 
 	if (doFork == TRUE) {
+		FILE *pidf;
 #if defined(__uClinux__)
 		vfork_daemon_rexec(0, 1, argc, argv, "-n");
 #else /* __uClinux__ */
 		if(daemon(0, 1) < 0)
 			bb_perror_msg_and_die("daemon");
 #endif /* __uClinux__ */
+
+		if ((pidf = fopen("/var/run/syslogd.pid", "w")) != NULL) {
+			fprintf(pidf, "%d\n", getpid());
+			fclose(pidf);
+		}
 	}
 	doSyslogd();
 


More information about the busybox mailing list