]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
For infinite timeout, we now resent the last request at TIMEOUT_MINI
authorRoy Marples <roy@marples.name>
Tue, 16 Jan 2007 17:54:07 +0000 (17:54 +0000)
committerRoy Marples <roy@marples.name>
Tue, 16 Jan 2007 17:54:07 +0000 (17:54 +0000)
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.

21 files changed:
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

index 3960c5f863c45251369c66efbe021952e318bc6d..893ad31e75ee0d856eea605f20b8611b8056eaae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 27c678a2ea23dd3712a990cc2e86706d3a5fac3b..e5708e2200476c60b7be736009327686b070c5ae 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -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: $(TARGET)
        $(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)
diff --git a/arp.c b/arp.c
index 2c9ff0ad6786f31cbe0941ca4603f9cb4758888e..4d210bc8465089b76e9557b1ef62dfed87f8dc53 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -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.
  *
diff --git a/arp.h b/arp.h
index 4dfd007d1f15bea7a6f59e4b99bd4c2ea158816f..25563c60d4b115c4d86ee4a66de058bcf1710c15 100644 (file)
--- a/arp.h
+++ b/arp.h
@@ -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
index 0116f84de93ce798abf74ae96874b91d2cecf4a7..0c0abedf331329cf0b01a5c9d8e147444d5ff2b5 100644 (file)
--- a/client.c
+++ b/client.c
@@ -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 @@ int dhcp_run (const options_t *options)
          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 @@ int dhcp_run (const options_t *options)
            {
            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:
index 3acbfeaf1ad9d62425ac96299ece4b56c2e38d62..88c460e17d469d24d48218874b2de5a9e22170c7 100644 (file)
--- a/client.h
+++ b/client.h
@@ -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.
  *
index 5739e4ff83e511f9b79bc5bd2a4a289760738ab1..c7a50e02abdd32e05a0cf5f4fea15901bb188dbb 100644 (file)
--- a/common.c
+++ b/common.c
@@ -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.
  *
index dee34d6d9e8490b798c6ff5beaaf6f1458a3026d..3ef15804234dc01d42ba0f9ccb3a639c2e921e79 100644 (file)
--- a/common.h
+++ b/common.h
@@ -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.
  *
index c7b26920b37e66503557af71d9e07cd8420a0f5c..3ff4d84df1ff07ba699d006e66235efe86a2c24b 100644 (file)
@@ -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 @@ static char *cleanmetas (const char *cstr)
   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 @@ static void exec_script (const char *script, const char *infofile,
     }
 
   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 int make_resolv (const char *ifname, const dhcp_t *dhcp)
 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 @@ static int make_ntp (const char *ifname, const dhcp_t *dhcp)
   fprintf (f, "driftfile " NTPDRIFTFILE "\n");
   fprintf (f, "logfile " NTPLOGFILE "\n");
   fclose (f);
+
+  exec_cmd (NTPSERVICE, NTPRESTARTARGS, NULL);
   return 0;
 }
 
@@ -240,6 +255,7 @@ static int make_nis (const char *ifname, const dhcp_t *dhcp)
 
   fclose (f);
 
+  exec_cmd (NISSERVICE, NISRESTARTARGS, NULL);
   return 0;
 }
 
index 59b7003db2ff15feec362e8cfeff50900091cc4b..a7e54632a88d69d72e88293c109c8fe8fe93a522 100644 (file)
@@ -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.
  *
diff --git a/dhcp.c b/dhcp.c
index 72ba37b35d5d34090487c7915e1886de05ce386d..3fa18bedd52ad497694e6378af76d5df24ac4cf3 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -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.
  *
diff --git a/dhcp.h b/dhcp.h
index 64de616169065654a0bc86c9469cfb8cb4ce8dac..b6fbfefcea56cb5990e84422591d6ae2f5a86125 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -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.
  *
index 0eb942e396f609f0d8a20a6932542715b2f1812e..feb03dbbda61f94becd92f6f4539a38ee71b1d36 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -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.
  *
index 1d55a09fc539f34b948c260e656d4afcd31d8d7e..25e7ef97a6429a57912a4dda349f20892906c4cc 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -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
index 2990817aebb95599b57b84bfe533b130e8c420f3..8ee0ad5ddfb2a44f3857c2bc7dea5524269d3392 100644 (file)
@@ -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.
  *
index bc1eaefb74e50d8e81df95ebcc87826b77a07bc1..131b42ef24bed0e2a8770187d4b3ada584e72034 100644 (file)
@@ -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.
  *
index d9e3700fc542cb6caa18b468a23fc3e41e796b07..303dadec18950361ae058d5c0fe5358de54f82b0 100644 (file)
--- a/logger.c
+++ b/logger.c
@@ -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.
  *
index d98d5cf0b663b69c6302ea65c972d5b19c5a5ecf..e37c820131c214c36705a39057fc51f9ac5a4e39 100644 (file)
--- a/logger.h
+++ b/logger.h
@@ -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.
  *
index d748948ae48477b25d3f6a7c744a7a35b96166e3..b80a9e154d49c799bb1cfef65a49bc41547a2e32 100644 (file)
@@ -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.
  *
 
 #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
index 07909086d4bb539e088c948eac0c11a7bee7fe4e..69c12ef2720deb85cbc947b91badd93b45ffe3e1 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -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.
index 3259b07023ccd3df4f3123b192dd3cc1693e9e74..beb60f48d8e2439b4ad9661db092b44263b9da19 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -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.