init_state(struct interface *ifp, int argc, char **argv)
{
struct if_options *ifo;
- const char *reason = NULL;
+ const char *reason;
configure_interface(ifp, argc, argv);
ifo = ifp->options;
ifo->options &= ~DHCPCD_IPV6RS;
}
- if (!(ifp->ctx->options & DHCPCD_TEST))
- script_runreason(ifp, "PREINIT");
-
+ reason = NULL; /* appease gcc */
if (ifo->options & DHCPCD_LINK) {
switch (carrier_status(ifp)) {
case LINK_DOWN:
ifp->carrier = LINK_UNKNOWN;
return;
}
- if (reason && !(ifp->ctx->options & DHCPCD_TEST))
- script_runreason(ifp, reason);
} else
ifp->carrier = LINK_UNKNOWN;
+
+ if (!(ifp->ctx->options & DHCPCD_TEST))
+ script_runreason(ifp, "PREINIT");
+
+ if (ifp->carrier != LINK_UNKNOWN && !(ifp->ctx->options & DHCPCD_TEST))
+ script_runreason(ifp, reason);
}
void
"interface",
"reason",
"pid",
+ "ifcarrier",
"ifmetric",
"ifwireless",
"ifflags",
if (ifp->ctx->options & DHCPCD_DUMPLEASE)
elen = 2;
else
- elen = 10;
+ elen = 11;
#define EMALLOC(i, l) if ((env[(i)] = malloc(l)) == NULL) goto eexit;
/* Make our env */
EMALLOC(2, e);
snprintf(env[2], e, "pid=%d", getpid());
EMALLOC(3, e);
- snprintf(env[3], e, "ifmetric=%d", ifp->metric);
+ snprintf(env[3], e, "ifcarrier=%s",
+ ifp->carrier == LINK_UNKNOWN ? "unknown" :
+ ifp->carrier == LINK_UP ? "up" : "down");
EMALLOC(4, e);
- snprintf(env[4], e, "ifwireless=%d", ifp->wireless);
+ snprintf(env[4], e, "ifmetric=%d", ifp->metric);
EMALLOC(5, e);
- snprintf(env[5], e, "ifflags=%u", ifp->flags);
+ snprintf(env[5], e, "ifwireless=%d", ifp->wireless);
EMALLOC(6, e);
- snprintf(env[6], e, "ifmtu=%d", get_mtu(ifp->name));
+ snprintf(env[6], e, "ifflags=%u", ifp->flags);
+ EMALLOC(7, e);
+ snprintf(env[7], e, "ifmtu=%d", get_mtu(ifp->name));
l = e = strlen("interface_order=");
TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
e += strlen(ifp2->name) + 1;
}
- EMALLOC(7, e);
- p = env[7];
+ EMALLOC(8, e);
+ p = env[8];
strlcpy(p, "interface_order=", e);
e -= l;
p += l;
}
*--p = '\0';
if (strcmp(reason, "TEST") == 0) {
- env[8] = strdup("if_up=false");
- env[9] = strdup("if_down=false");
+ env[9] = strdup("if_up=false");
+ env[10] = strdup("if_down=false");
} else if ((dhcp && state && state->new)
#ifdef INET6
|| (dhcp6 && d6_state && d6_state->new)
#endif
)
{
- env[8] = strdup("if_up=true");
- env[9] = strdup("if_down=false");
+ env[9] = strdup("if_up=true");
+ env[10] = strdup("if_down=false");
} else {
- env[8] = strdup("if_up=false");
- env[9] = strdup("if_down=true");
+ env[9] = strdup("if_up=false");
+ env[10] = strdup("if_down=true");
}
- if (env[8] == NULL || env[9] == NULL)
+ if (env[9] == NULL || env[10] == NULL)
goto eexit;
if (*ifp->profile) {
e = strlen("profile=") + strlen(ifp->profile) + 2;
env = nenv;
EMALLOC(elen, e);
snprintf(env[elen++], e, "new_ssid=%s", ifp->ssid);
- }
- else if (strcmp(reason, "NOCARRIER") == 0) {
+ } else if (strcmp(reason, "NOCARRIER") == 0) {
nenv = realloc(env, sizeof(char *) * (elen + 2));
if (nenv == NULL)
goto eexit;