]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add knobs to work with RedHat, Slackware and generic SYSV init scripts
authorRoy Marples <roy@marples.name>
Fri, 9 Nov 2007 20:48:51 +0000 (20:48 +0000)
committerRoy Marples <roy@marples.name>
Fri, 9 Nov 2007 20:48:51 +0000 (20:48 +0000)
Makefile
README
config.h
configure.c
dhcpcd.c

index 8f2ba4adb4670c402d892165e795cffa76b8f5e8..584512976154d442147cf71635d538701cb11e29 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -62,8 +62,14 @@ _HAVE_FORK_SH = if [ "$(HAVE_FORK)" = "yes" ]; then \
 _HAVE_FORK != $(_HAVE_FORK_SH)
 FORK = $(_HAVE_FORK)$(shell $(_HAVE_FORK_SH))
 
-# Work out if we use Open RC or BSD RC
-_RC_SH = if [ -d /etc/init.d ]; then echo "-DENABLE_ORC"; elif [ -d /etc/rc.d ]; then echo "-DENABLE_BRC"; fi
+# Work out how to restart services 
+_RC_SH = if [ -n "$(HAVE_INIT)" ]; then \
+                [ "$(HAVE_INIT)" = "no" ] || echo "-DENABLE_$(HAVE_INIT)"; \
+                elif [ -x /sbin/runscript ]; then echo "-DENABLE_ORC"; \
+                elif [ -x /sbin/service ]; then echo "-DENABLE_SERVICE"; \
+                elif [ -d /etc/rc.d ]; then echo "-DENABLE_BRC"; \
+                elif [ -d /etc/init.d ]; then echo "-DENABLE_SYSV"; \
+                fi
 _RC != $(_RC_SH)
 RC = $(_RC)$(shell $(_RC_SH))
 
diff --git a/README b/README
index f5a60849ca08674ba21171bf38f818debde83e6e..11e56c9152c5c42c99f962fa1ab1da567c9af17b 100644 (file)
--- a/README
+++ b/README
@@ -24,3 +24,10 @@ Notes
 -----
 If you're cross compiling you may need to send HAVE_FORK=yes or HAVE_FORK=no
 to the make command to avoid to automatic test.
+
+We try and detect how to restart ntp and ypbind, you can override this with
+HAVE_INIT=no or force one of these values
+ORC      (OpenRC as used by Gentoo (forked from baselayout))
+BRC      (BSD RC system - /etc/rc.d/ntpd restart )
+SERVICE  (RedHat service command - service ntpd restart)
+SYSV     (SYSV style - /etc/init.d/ntpd restart)
index b316ceab37952294dc4cbd9bba095f93985370f4..ac432cd25831210c3fca8ad3ebe9afafe1a45d2a 100644 (file)
--- a/config.h
+++ b/config.h
 
 #define DUIDFILE            CONFIGDIR "/" PACKAGE ".duid"
 
-/* ORC is the Open Run Control, forked from Gentoo's baselayout package
- * RC is a BSD style Run Control system */
+/* ORC is Open Run Control, forked from Gentoo's baselayout package
+ * BRC is BSD style Run Control
+ * SRC is Slackware Run Control
+ * SERVICE is RedHat
+ * SYSV should cover everthing else */
 #ifdef ENABLE_ORC
-#define NISSERVICE          ETCDIR "/init.d/ypbind"
-#define NISRESTARTARGS      "--nodeps", "--quiet", "conditionalrestart"
-#define NTPSERVICE          ETCDIR "/init.d/ntpd"
-#define NTPRESTARTARGS      "--nodeps", "--quiet", "conditionalrestart"
-#define OPENNTPSERVICE      ETCDIR "/init.d/ntpd"
-#define OPENNTPRESTARTARGS  "--nodeps", "--quiet", "conditionalrestart"
+# define SERVICE             "ORC"
+# define NISSERVICE          ETCDIR "/init.d/ypbind"
+# define NISRESTARTARGS      "--nodeps", "--quiet", "conditionalrestart"
+# define NTPSERVICE          ETCDIR "/init.d/ntpd"
+# define NTPRESTARTARGS      "--nodeps", "--quiet", "conditionalrestart"
 #elif ENABLE_BRC
-#define NISSERVICE          ETCDIR "/rc.d/ypbind"
-#define NISRESTARTARGS      "restart"
-#define NTPSERVICE          ETCDIR "/rc.d/ntpd"
-#define NTPRESTARTARGS      "restart"
-#define OPENNTPSERVICE      ETCDIR "/rc.d/ntpd"
-#define OPENNTPRESTARTARGS  "restart"
+# define SERVICE             "BRC"
+# define NISSERVICE          ETCDIR "/rc.d/ypbind"
+# define NISRESTARTARGS      "restart"
+# define NTPSERVICE          ETCDIR "/rc.d/ntpd"
+# define NTPRESTARTARGS      "restart"
+#elif ENABLE_SRC
+# define SERVICE             "SRC"
+# define NISSERVICE          ETCDIR "/rc.d/rc.ypbind"
+# define NISRESTARTARGS      "restart"
+# define NTPSERVICE          ETCDIR "/rc.d/rc.ntpd"
+# define NTPRESTARTARGS      "restart"
+#elif ENABLE_SERVICE
+# define SERVICE             "SERVICE"
+# define NISSERVICE          "service"
+# define NISRESTARTARGS      "ypbind", "restart"
+# define NTPSERVICE          "service"
+# define NTPRESTARTARGS      "ntpd", "restart"
+#elif ENABLE_SYSV
+# define SERVICE             "SYSV"
+# define NISSERVICE          ETCDIR "/init.d/ypbind"
+# define NISRESTARTARGS      "restart"
+# define NTPSERVICE          ETCDIR "/init.d/ntpd"
+# define NTPRESTARTARGS      "restart"
 #else
-#undef ENABLE_NIS
-#undef ENABLE_NTP
+# undef ENABLE_NIS
+# undef ENABLE_NTP
 #endif
 
 #endif
index ca832aa99039c04bcc0a2110e1569e675557ec50..2fa95091ecfa0b4557aa457892ce95fdb790ad74 100644 (file)
@@ -293,17 +293,29 @@ static int make_ntp (const char *ifname, const dhcp_t *dhcp)
 #endif
 
 #ifdef NTPSERVICE
-       if (restart_ntp)
-               retval += exec_cmd (NTPSERVICE, NTPRESTARTARGS, (char *) NULL);
+       if (restart_ntp) {
+#ifdef NTPCHECK
+               if (system (NTPCHECK) == 0)
+#endif
+                       retval += exec_cmd (NTPSERVICE, NTPRESTARTARGS, (char *) NULL);
+       }
 #endif
 
 #if defined (NTPSERVICE) && defined (OPENNTPSERVICE)
        if (restart_openntp &&
                (strcmp (NTPSERVICE, OPENNTPSERVICE) != 0 || ! restart_ntp))
-               retval += exec_cmd (OPENNTPSERVICE, OPENNTPRESTARTARGS, (char *) NULL);
+       {
+#ifdef OPENNTPCHECK
+               if (system (OPENNTPCHECK) == 0)
+#endif
+                       retval += exec_cmd (OPENNTPSERVICE, OPENNTPRESTARTARGS, (char *) NULL);
+       }
 #elif defined (OPENNTPSERVICE) && ! defined (NTPSERVICE)
-       if (restart_openntp) 
-               retval += exec_cmd (OPENNTPSERVICE, OPENNTPRESTARTARGS, (char *) NULL);
+       if (restart_openntp) {
+#ifdef OPENNTPCHECK
+               if (system (OPENNTPCHECK) == 0)
+#endif
+                       retval += exec_cmd (OPENNTPSERVICE, OPENNTPRESTARTARGS, (char *) NULL);
 #endif
 
        return retval;
@@ -345,7 +357,10 @@ static int make_nis (const char *ifname, const dhcp_t *dhcp)
        free (prefix);
        fclose (f);
 
-       exec_cmd (NISSERVICE, NISRESTARTARGS, (char *) NULL);
+#ifdef NISCHECK
+       if (system (NISCHECK) == 0)
+#endif
+               exec_cmd (NISSERVICE, NISRESTARTARGS, (char *) NULL);
        return 0;
 }
 #endif
index f783799260d794f22f908066b637d2cf685b050e..86ce2519df66540866fe1005c64676080a0267de 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -403,10 +403,8 @@ int main(int argc, char **argv)
 #ifdef ENABLE_NTP
                                " NTP"
 #endif
-#ifdef ENABLE_ORC
-                               " ORC"
-#elif ENABLE_BRC
-                               " BRC"
+#ifdef SERVICE
+                               " " SERVICE
 #endif
 #ifdef ENABLE_RESOLVCONF
                                " RESOLVCONF"