changeset 2521:1bea2300e658 draft

Ensure we init before forking, but run the preinit scripts afterwards
author Roy Marples <roy@marples.name>
date Thu, 05 Jun 2014 13:03:49 +0000
parents 1d6444e11b21
children b51f8624a660
files dhcpcd.c
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/dhcpcd.c	Thu Jun 05 12:33:18 2014 +0000
+++ b/dhcpcd.c	Thu Jun 05 13:03:49 2014 +0000
@@ -674,7 +674,6 @@
 init_state(struct interface *ifp, int argc, char **argv)
 {
 	struct if_options *ifo;
-	const char *reason;
 
 	configure_interface(ifp, argc, argv);
 	ifo = ifp->options;
@@ -696,9 +695,15 @@
 		syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name);
 		ifo->options &= DHCPCD_IPV6;
 	}
+}
+
+static void
+run_preinit(struct interface *ifp)
+{
+	const char *reason;
 
 	reason = NULL; /* appease gcc */
-	if (ifo->options & DHCPCD_LINK) {
+	if (ifp->options->options & DHCPCD_LINK) {
 		switch (if_carrier(ifp)) {
 		case LINK_DOWN:
 			ifp->carrier = LINK_DOWN;
@@ -772,6 +777,7 @@
 		}
 		if (action > 0) {
 			init_state(ifp, ctx->argc, ctx->argv);
+			run_preinit(ifp);
 			dhcpcd_startinterface(ifp);
 		}
 	}
@@ -849,6 +855,7 @@
 		} else {
 			TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
 			init_state(ifp, argc, argv);
+			run_preinit(ifp);
 			dhcpcd_startinterface(ifp);
 		}
 	}
@@ -1545,12 +1552,16 @@
 		}
 	}
 
+	TAILQ_FOREACH(ifp, ctx.ifaces, next) {
+		init_state(ifp, argc, argv);
+	}
+
 	if (ctx.options & DHCPCD_BACKGROUND && dhcpcd_daemonise(&ctx))
 		goto exit_success;
 
 	opt = 0;
 	TAILQ_FOREACH(ifp, ctx.ifaces, next) {
-		init_state(ifp, argc, argv);
+		run_preinit(ifp);
 		if (ifp->carrier != LINK_DOWN)
 			opt = 1;
 	}