[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    udhcpc's disappearing pid file
From:       "Gabriel L. Somlo" <somlo () cmu ! edu>
Date:       2007-04-30 20:46:27
Message-ID: 20070430204627.GC15142 () hedwig ! net ! cmu ! edu
[Download RAW message or body]

ifupdown.c is using pid files to keep track of things like the udhcpc
process used to configure an interface (so it can track it down and
kill it later, when the interface is deconfigured).

Trouble is, in the latest svn version, the pid file pulls a
disappearing act after udhcpc is started.

Reason is that somewhere downriver of udhcp_make_pidfile() (actually
in create_pidfile() to be precise) we set an atexit(pidfile_delete).
This would be nice, except that when udhcpc goes to background, the
dying parent removes the pid file, and the child doesn't put one of
its own in place.

The attached patch attempts to fix that problem. Please let me know
what you think, and apply if it looks ok.

Gabriel


diff -NarU5 busybox-svn-18532.orig/networking/udhcp/common.c busybox-svn-18532/networking/udhcp/common.c
--- busybox-svn-18532.orig/networking/udhcp/common.c	2007-04-29 21:52:09.000000000 -0400
+++ busybox-svn-18532/networking/udhcp/common.c	2007-04-30 16:42:15.000000000 -0400
@@ -24,17 +24,21 @@
 	return info.uptime;
 }
 
 #if ENABLE_FEATURE_PIDFILE
 static const char *saved_pidfile;
+#endif
 
-static void pidfile_delete(void)
+void udhcp_delete_pidfile(void)
 {
-	if (saved_pidfile)
+#if ENABLE_FEATURE_PIDFILE
+	if (saved_pidfile) {
 		remove_pidfile(saved_pidfile);
-}
+		saved_pidfile = NULL;
+	}
 #endif
+}
 
 static void create_pidfile(const char *pidfile)
 {
 	if (!pidfile)
 		return;
@@ -44,11 +48,11 @@
 		return;
 	}
 #if ENABLE_FEATURE_PIDFILE
 	/* lockf(pid_fd, F_LOCK, 0); */
 	if (!saved_pidfile)
-		atexit(pidfile_delete);
+		atexit(udhcp_delete_pidfile);
 	saved_pidfile = pidfile;
 #endif
 }
 
 void udhcp_make_pidfile(const char *pidfile)
diff -NarU5 busybox-svn-18532.orig/networking/udhcp/common.h busybox-svn-18532/networking/udhcp/common.h
--- busybox-svn-18532.orig/networking/udhcp/common.h	2007-04-29 21:52:09.000000000 -0400
+++ busybox-svn-18532/networking/udhcp/common.h	2007-04-30 16:38:14.000000000 -0400
@@ -59,10 +59,11 @@
 
 
 /**/
 
 void udhcp_make_pidfile(const char *pidfile);
+void udhcp_delete_pidfile(void);
 
 void udhcp_run_script(struct dhcpMessage *packet, const char *name);
 
 // Still need to clean these up...
 
diff -NarU5 busybox-svn-18532.orig/networking/udhcp/dhcpc.c busybox-svn-18532/networking/udhcp/dhcpc.c
--- busybox-svn-18532.orig/networking/udhcp/dhcpc.c	2007-04-29 21:52:09.000000000 -0400
+++ busybox-svn-18532/networking/udhcp/dhcpc.c	2007-04-30 16:42:08.000000000 -0400
@@ -105,10 +105,12 @@
 }
 
 
 static void client_background(void)
 {
+	/* remove parent's pidfile */
+	udhcp_delete_pidfile();
 #ifdef __uClinux__
 	bb_error_msg("cannot background in uclinux (yet)");
 /* ... mainly because udhcpc calls client_background()
  * in _the _middle _of _udhcpc _run_, not at the start!
  * If that will be properly disabled for NOMMU, client_background()
@@ -118,10 +120,12 @@
 	bb_daemonize(DAEMON_CHDIR_ROOT);
 	logmode &= ~LOGMODE_STDIO;
 #endif
 	client_config.foreground = 1; /* Do not fork again. */
 	client_config.background_if_no_lease = 0;
+	/* redo pidfile, this time from the background process */
+	udhcp_make_pidfile(client_config.pidfile);
 }
 
 
 static uint8_t* alloc_dhcp_option(int code, const char *str, int extra)
 {
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic