changeset 48:f61d0c281545 draft

For infinite timeout, we now resent the last request at TIMEOUT_MINI intervals like we do otherwise. We now return a non zero exit code on SIGTERM and SIGINT if we have not forked into the background. When NIS and/or NTP servers are updated, we restart the service for them if we can.
author Roy Marples <roy@marples.name>
date Tue, 16 Jan 2007 17:54:07 +0000
parents 817185cc8dec
children 945de31c6944
files ChangeLog Makefile arp.c arp.h client.c client.h common.c common.h configure.c configure.h dhcp.c dhcp.h dhcpcd.c dhcpcd.h interface.c interface.h logger.c logger.h pathnames.h socket.c socket.h
diffstat 21 files changed, 94 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Jan 07 11:09:59 2007 +0000
+++ b/ChangeLog	Tue Jan 16 17:54:07 2007 +0000
@@ -1,3 +1,10 @@
+For infinite timeout, we now resent the last request at TIMEOUT_MINI
+intervals like we do otherwise.
+We now return a non zero exit code on SIGTERM and SIGINT if we have not
+forked into the background.
+When NIS and/or NTP servers are updated, we restart the service for them
+if we can.
+
 dhcpcd-3.0.9
 Add static routes before any default routes as a router may require a host
 route in the static routes.
--- a/Makefile	Sun Jan 07 11:09:59 2007 +0000
+++ b/Makefile	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 # Should work for both GNU make and BSD make
 
-VERSION = 3.0.9
+VERSION = 3.0.10_pre1
 
 CFLAGS ?= -O2 -pipe
 
@@ -59,7 +59,7 @@
 	$(INSTALL) -m 0755 $(MAN8_TARGETS) $(MANDIR)/man8
 
 clean:
-	rm -f $(TARGET) $(dhcpcd_H) *.o *~
+	rm -f $(TARGET) $(dhcpcd_H) *.o *~ *.core
 
 dist:
 	$(INSTALL) -m 0755 -d /tmp/dhcpcd-$(VERSION)
--- a/arp.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/arp.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/arp.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/arp.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2005 - 2007 Roy Marples <uberlord@gentoo.org>
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
--- a/client.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/client.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
@@ -172,8 +172,16 @@
 	  if (options->timeout == 0 || dhcp->leasetime == (unsigned) -1)
 	    {
 	      logger (LOG_DEBUG, "waiting on select for infinity");
-	      maxfd = signal_fd_set (&rset, iface->fd);
-	      retval = select (maxfd + 1, &rset, NULL, NULL, NULL);
+	      retval = 0;
+	      while (retval == 0)
+		{
+		  tv.tv_sec = TIMEOUT_MINI;
+		  tv.tv_usec = 0;
+		  maxfd = signal_fd_set (&rset, iface->fd);
+		  retval = select (maxfd + 1, &rset, NULL, NULL, &tv);
+		  if (retval == 0)
+		    SEND_MESSAGE (last_type);
+		}
 	    }
 	  else
 	    {
@@ -216,12 +224,12 @@
 	    {
 	    case SIGINT:
 	      logger (LOG_INFO, "receieved SIGINT, stopping");
-	      retval = 0;
+	      retval = (! daemonised);
 	      goto eexit;
 
 	    case SIGTERM:
 	      logger (LOG_INFO, "receieved SIGTERM, stopping");
-	      retval = 0;
+	      retval = (! daemonised);
 	      goto eexit;
 
 	    case SIGALRM:
--- a/client.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/client.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/common.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/common.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/common.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/common.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/configure.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/configure.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  *
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <netdb.h>
 #include <resolv.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
 
@@ -74,11 +75,50 @@
   return b;
 }
 
+/* IMPORTANT: Ensure that the last parameter is NULL when calling */
+static int exec_cmd (const char *cmd, const char *args, ...)
+{
+  va_list va;
+  pid_t pid;
+  char **argv;
+  int n = 1;
+
+  va_start (va, args);
+  while (va_arg (va, char *) != NULL)
+    n++;
+  va_end (va);
+  argv = alloca ((n + 1) * sizeof (*argv));
+  if (argv == NULL)
+    {
+      errno = ENOMEM;
+      return -1;
+    }
+
+  va_start (va, args);
+  n = 2;
+  argv[0] = (char *) cmd;
+  argv[1] = (char *) args;
+  while ((argv[n] = va_arg (va, char *)) != NULL)
+    n++;
+  va_end (va);
+
+  if ((pid = fork ()) == 0)
+    {
+      if (execve (cmd, argv, NULL) && errno != ENOENT)
+	logger (LOG_ERR, "error executing \"%s\": %s",
+		cmd, strerror (errno));
+      exit (0);
+    }
+  else if (pid == -1)
+    logger (LOG_ERR, "fork: %s", strerror (errno));
+
+  return 0;
+}
+
 static void exec_script (const char *script, const char *infofile,
 			 const char *arg)
 {
   struct stat buf;
-  pid_t pid;
 
   if (! script || ! infofile || ! arg)
     return;
@@ -91,19 +131,7 @@
     }
 
   logger (LOG_DEBUG, "exec \"%s %s %s\"", script, infofile, arg);
-
-  /* We don't wait for the user script to finish - do we trust it? */
-  /* Don't use vfork as we lose our memory when dhcpcd exits
-     causing the script to fail */
-  if ((pid = fork ()) == 0)
-    {
-      if (execle (script, script, infofile, arg, NULL, NULL))
-	logger (LOG_ERR, "error executing \"%s %s %s\": %s",
-		script, infofile, arg, strerror (errno));
-      exit (0);
-    }
-  else if (pid == -1)
-    logger (LOG_ERR, "fork: %s", strerror (errno));
+  exec_cmd (script, infofile, arg, NULL);
 }
 
 static int make_resolv (const char *ifname, const dhcp_t *dhcp)
@@ -157,27 +185,12 @@
 static void restore_resolv(const char *ifname)
 {
   struct stat buf;
-  pid_t pid;
 
   if (stat (RESOLVCONF, &buf) < 0)
     return;
 
   logger (LOG_DEBUG, "removing information from resolvconf");
-
-  /* Don't wait around here as we should only be called when
-     dhcpcd is closing down and something may do a kill -9
-     if we take too long */
-  /* Don't use vfork as we lose our memory when dhcpcd exits
-     causing the script to fail */
-  if ((pid = fork ()) == 0)
-    {
-      if (execle (RESOLVCONF, RESOLVCONF, "-d", ifname, NULL, NULL))
-	logger (LOG_ERR, "error executing \"%s -d %s\": %s",
-		RESOLVCONF, ifname, strerror (errno));
-      exit (0);
-    }
-  else if (pid == -1)
-    logger (LOG_ERR, "fork: %s", strerror (errno));
+  exec_cmd (RESOLVCONF, "-d", ifname, NULL);
 }
 
 static int make_ntp (const char *ifname, const dhcp_t *dhcp)
@@ -206,6 +219,8 @@
   fprintf (f, "driftfile " NTPDRIFTFILE "\n");
   fprintf (f, "logfile " NTPLOGFILE "\n");
   fclose (f);
+
+  exec_cmd (NTPSERVICE, NTPRESTARTARGS, NULL);
   return 0;
 }
 
@@ -240,6 +255,7 @@
 
   fclose (f);
 
+  exec_cmd (NISSERVICE, NISRESTARTARGS, NULL);
   return 0;
 }
 
--- a/configure.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/configure.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/dhcp.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/dhcp.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/dhcp.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/dhcp.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/dhcpcd.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/dhcpcd.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/dhcpcd.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/dhcpcd.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
--- a/interface.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/interface.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/interface.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/interface.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/logger.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/logger.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/logger.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/logger.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
--- a/pathnames.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/pathnames.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2005 - 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2005 - 2007 Roy Marples <uberlord@gentoo.org>
  *
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
  *
@@ -28,9 +28,17 @@
 
 #define ETCDIR			"/etc"
 #define RESOLVFILE		ETCDIR "/resolv.conf"
+
 #define NISFILE			ETCDIR "/yp.conf"
+#define NISSERVICE		ETCDIR "/init.d/ypbind"
+#define NISRESTARTARGS		"--quiet", "conditionalrestart"
+
 #define NTPFILE			ETCDIR "/ntp.conf"
 #define NTPDRIFTFILE		ETCDIR "/ntp.drift"
+#define NTPLOGFILE		"/var/log/ntp.log"
+#define NTPSERVICE		ETCDIR "/init.d/ntpd"
+#define NTPRESTARTARGS		"--quiet", "conditionalrestart"
+
 #define DEFAULT_SCRIPT		ETCDIR "/" PACKAGE ".sh"
 
 #define STATEDIR		"/var"
@@ -39,6 +47,4 @@
 #define CONFIGDIR		STATEDIR "/lib/" PACKAGE
 #define INFOFILE		CONFIGDIR "/" PACKAGE "-%s.info"
 
-#define NTPLOGFILE		"/var/log/ntp.log"
-
 #endif
--- a/socket.c	Sun Jan 07 11:09:59 2007 +0000
+++ b/socket.c	Tue Jan 16 17:54:07 2007 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * although a lot was lifted from udhcp
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.
--- a/socket.h	Sun Jan 07 11:09:59 2007 +0000
+++ b/socket.h	Tue Jan 16 17:54:07 2007 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon -
- * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org>
+ * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org>
  * although a lot was lifted from udhcp
  * 
  * dhcpcd is an RFC2131 compliant DHCP client daemon.