From: Roy Marples Date: Fri, 9 Nov 2007 20:48:51 +0000 (+0000) Subject: Add knobs to work with RedHat, Slackware and generic SYSV init scripts X-Git-Tag: v3.2.3~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=816ad2eab1a0dc05931d71379859682fe6b00da8;p=thirdparty%2Fdhcpcd.git Add knobs to work with RedHat, Slackware and generic SYSV init scripts --- diff --git a/Makefile b/Makefile index 8f2ba4ad..58451297 100644 --- 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 f5a60849..11e56c91 100644 --- 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) diff --git a/config.h b/config.h index b316ceab..ac432cd2 100644 --- a/config.h +++ b/config.h @@ -62,25 +62,44 @@ #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 diff --git a/configure.c b/configure.c index ca832aa9..2fa95091 100644 --- a/configure.c +++ b/configure.c @@ -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 diff --git a/dhcpcd.c b/dhcpcd.c index f7837992..86ce2519 100644 --- 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"