]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move /etc/dhcpcd.conf to /etc/dhcpcd/dhcpcd.conf etc_dhcpcd
authorRoy Marples <roy@marples.name>
Mon, 16 Jun 2025 11:59:16 +0000 (12:59 +0100)
committerRoy Marples <roy@marples.name>
Mon, 16 Jun 2025 11:59:16 +0000 (12:59 +0100)
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.

hooks/dhcpcd-run-hooks.8.in
hooks/dhcpcd-run-hooks.in
src/Makefile
src/defs.h
src/dhcpcd.8.in
src/if-options.c

index 73859b37fdc0edcdac5af8cd76979c350f724a05..e554de435f9a7a1c8e2a0f3a267d1bc61b0d3009 100644 (file)
@@ -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
index 91df64b1a8093f94158ec9d1f90c47f16c605023..eb28da6f505a299a251bbb3dc748a31a01331ddf 100644 (file)
@@ -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
index 8027778ffcfd26da154a6c978d224f393acc80d5..1d5d8b9c8a9eba08eeac8fc7d91920496e3004c3 100644 (file)
@@ -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
        
index c527c7936ac0ce37723fe0933f14ec56ad6a8668..256bd1236bb970d60649c1533e705cdd8062d66e 100644 (file)
 #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"
index ebbf06c0f737eda05c8aede08c44cc270d359a41..ed0a77087cd54f271d2401c59badca6a57da2c15 100644 (file)
@@ -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
index 1b256fa9afa17970381264632d4ba0ceaa2caaca..7166c7b3ecb4fe02d94b9c2956ac853c59fe193e 100644 (file)
@@ -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 ... */