From: Roy Marples Date: Mon, 16 Jun 2025 11:59:16 +0000 (+0100) Subject: Move /etc/dhcpcd.conf to /etc/dhcpcd/dhcpcd.conf X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fetc_dhcpcd;p=thirdparty%2Fdhcpcd.git Move /etc/dhcpcd.conf to /etc/dhcpcd/dhcpcd.conf Rationale: packages want to drop hook scripts into /etc Having /etc/dhcpcd now allows us to have /etc/dhcpcd/enter-hooks.d and /etc/dhcpcd/exit-hooks.d which allows this. Users can also now create symlinks from installed example hooks into /etc rather than having to edit a singular file. Fixes #494. --- diff --git a/hooks/dhcpcd-run-hooks.8.in b/hooks/dhcpcd-run-hooks.8.in index 73859b37..e554de43 100644 --- a/hooks/dhcpcd-run-hooks.8.in +++ b/hooks/dhcpcd-run-hooks.8.in @@ -218,11 +218,15 @@ space-separated list of delegated prefixes. When .Nm runs, it loads -.Pa @SYSCONFDIR@/dhcpcd.enter-hook , +.Pa @SYSCONFDIR@/dhcpcd/enter-hook , any scripts found in +.Pa @SYSCONFDIR@/dhcpcd/enter-hooks.d , +in lexical order, any scripts found in .Pa @HOOKDIR@ -in lexical order, then finally -.Pa @SYSCONFDIR@/dhcpcd.exit-hook . +in lexical order, any scripts found in +.Pa @SYSCONFDIR@/dhcpcd/exit-hooks.d . +in lexical order, and then finally +.Pa @SYSCONFDIR@/dhcpcd/exit-hook . .Sh SEE ALSO .Xr dhcpcd 8 .Sh AUTHORS diff --git a/hooks/dhcpcd-run-hooks.in b/hooks/dhcpcd-run-hooks.in index 91df64b1..eb28da6f 100644 --- a/hooks/dhcpcd-run-hooks.in +++ b/hooks/dhcpcd-run-hooks.in @@ -335,7 +335,11 @@ service_condcommand() # /etc/resolv.conf how they want and stop the system scripts ever updating it. for hook in \ @SYSCONFDIR@/dhcpcd.enter-hook \ + @SYSCONFDIR@/dhcpcd/enter-hook \ + @SYSCONFDIR@/dhcpcd/enter-hooks.d/* \ @HOOKDIR@/* \ + @SYSCONFDIR@/dhcpcd/exit-hooks.d/* + @SYSCONFDIR@/dhcpcd/exit-hook @SYSCONFDIR@/dhcpcd.exit-hook do case "$hook" in diff --git a/src/Makefile b/src/Makefile index 8027778f..1d5d8b9c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -94,14 +94,21 @@ _maninstall: ${MAN5} ${MAN8} ${INSTALL} -m ${MANMODE} ${MAN8} ${DESTDIR}${MANDIR}/man8 _confinstall: - ${INSTALL} -d ${DESTDIR}${SYSCONFDIR} + ${INSTALL} -d ${DESTDIR}${SYSCONFDIR}/dhcpcd + # Copy existig config to new location if not present + if ! [ -e ${DESTDIR}${SYSCONFDIR}/dhcpcd/dhcpcd.conf ] && \ + [ -e ${DESTDIR}${SYSCONFDIR}/dhcpcd.conf ]; then \ + mv ${DESTDIR}${SYSCONFDIR}/dhcpcd.conf \ + ${DESTDIR}${SYSCONFDIR}/dhcpcd; \ + fi # Install a new default config if not present - if ! [ -e ${DESTDIR}${SYSCONFDIR}/dhcpcd.conf ]; then \ - ${INSTALL} -m ${CONFMODE} dhcpcd.conf ${DESTDIR}${SYSCONFDIR}; \ + if ! [ -e ${DESTDIR}${SYSCONFDIR}/dhcpcd/dhcpcd.conf ]; then \ + ${INSTALL} -m ${CONFMODE} dhcpcd.conf \ + ${DESTDIR}${SYSCONFDIR}/dhcpcd; \ if [ "${UNCOMMENT_NTP}" = yes ]; then \ ${SED} -i \ -e 's/#option ntp_servers/option ntp_servers/' \ - ${DESTDIR}/${SYSCONFDIR}/dhcpcd.conf; \ + ${DESTDIR}/${SYSCONFDIR}/dhcpcd/dhcpcd.conf; \ fi; \ fi diff --git a/src/defs.h b/src/defs.h index c527c793..256bd123 100644 --- a/src/defs.h +++ b/src/defs.h @@ -36,7 +36,10 @@ #endif #ifndef CONFIG -# define CONFIG SYSCONFDIR "/" PACKAGE ".conf" +# define CONFIG SYSCONFDIR "/" PACKAGE "/" PACKAGE ".conf" +#endif +#ifndef CONFIG_OLD +# define CONFIG_OLD SYSCONFDIR "/" PACKAGE ".conf" #endif #ifndef SCRIPT # define SCRIPT LIBEXECDIR "/" PACKAGE "-run-hooks" diff --git a/src/dhcpcd.8.in b/src/dhcpcd.8.in index ebbf06c0..ed0a7708 100644 --- a/src/dhcpcd.8.in +++ b/src/dhcpcd.8.in @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd May 8, 2025 +.Dd June 16, 2025 .Dt DHCPCD 8 .Os .Sh NAME @@ -217,7 +217,7 @@ To work with these devices they either need to be specified on the command line, be listed in .Fl Fl allowinterfaces or have an interface directive in -.Pa @SYSCONFDIR@/dhcpcd.conf . +.Pa @SYSCONFDIR@/dhcpcd/dhcpcd.conf . .Ss Hooking into events .Nm runs @@ -335,7 +335,7 @@ encodes the FQDN hostname as specified in .Li RFC 1035 . .It Fl f , Fl Fl config Ar file Specify a config to load instead of -.Pa @SYSCONFDIR@/dhcpcd.conf . +.Pa @SYSCONFDIR@/dhcpcd/dhcpcd.conf . .Nm always processes the config file before any command line options. .It Fl h , Fl Fl hostname Ar hostname @@ -821,9 +821,11 @@ If using a DUID in place of the ClientID, edit accordingly. .Sh FILES .Bl -ohang -.It Pa @SYSCONFDIR@/dhcpcd.conf +.It Pa @SYSCONFDIR@/dhcpcd/dhcpcd.conf Configuration file for dhcpcd. If you always use the same options, put them here. +.It Pa @SYSCONFDIR@/dhcpcd.conf +Old configuration file for dhcpcd used if one in the new location does not exist. .It Pa @SCRIPT@ Bourne shell script that is run to configure or de-configure an interface. .It Pa @LIBDIR@/dhcpcd/dev diff --git a/src/if-options.c b/src/if-options.c index 1b256fa9..7166c7b3 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -2830,6 +2830,16 @@ read_config(struct dhcpcd_ctx *ctx, /* Parse our options file */ buflen = dhcp_readfile(ctx, ctx->cffile, buf, sizeof(buf)); + /* If we can't find the config file in the new location, + * retry the old location. */ + if (buflen == -1 && errno == ENOENT && + strcmp(ctx->cffile, CONFIG) == 0) + { + const int olderrno = errno; + buflen = dhcp_readfile(ctx, CONFIG_OLD, buf, sizeof(buf)); + errno = olderrno; + } + if (buflen == -1) { /* dhcpcd can continue without it, but no DNS options * would be requested ... */