From: Roy Marples Date: Wed, 10 Apr 2019 20:36:51 +0000 (+0100) Subject: script: Assign a default script X-Git-Tag: v7.2.0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab3e580dfa21996ad882167c8918e71b6e7c1ce8;p=thirdparty%2Fdhcpcd.git script: Assign a default script Fixes a dumb mistake I made earlier. --- diff --git a/src/if-options.c b/src/if-options.c index dee07eb1..c70d18a1 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -207,6 +207,8 @@ const struct option cf_options[] = { {NULL, 0, NULL, '\0'} }; +static const char *default_script = SCRIPT; + static char * add_environ(struct if_options *ifo, const char *value, int uniq) { @@ -708,7 +710,8 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, break; case 'c': ARG_REQUIRED; - free(ifo->script); + if (ifo->script != default_script) + free(ifo->script); s = parse_string(NULL, 0, arg); if (s == 0) { ifo->script = NULL; @@ -716,6 +719,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, } dl = (size_t)s; if (s == -1 || (ifo->script = malloc(dl)) == NULL) { + ifo->script = NULL; logerr(__func__); return -1; } @@ -2291,6 +2295,7 @@ default_config(struct dhcpcd_ctx *ctx) ifo->options |= DHCPCD_IF_UP | DHCPCD_LINK | DHCPCD_INITIAL_DELAY; ifo->timeout = DEFAULT_TIMEOUT; ifo->reboot = DEFAULT_REBOOT; + ifo->script = UNCONST(default_script); ifo->metric = -1; ifo->auth.options |= DHCPCD_AUTH_REQUIRE; TAILQ_INIT(&ifo->routes); @@ -2640,7 +2645,8 @@ free_options(struct dhcpcd_ctx *ctx, struct if_options *ifo) free(ifo->config); } rt_headclear0(ctx, &ifo->routes, AF_UNSPEC); - free(ifo->script); + if (ifo->script != default_script) + free(ifo->script); free(ifo->arping); free(ifo->blacklist); free(ifo->fallback); diff --git a/src/script.c b/src/script.c index deeda527..451b0308 100644 --- a/src/script.c +++ b/src/script.c @@ -718,7 +718,7 @@ script_runreason(const struct interface *ifp, const char *reason) if (ifp->options->script == NULL) goto send_listeners; - argv[0] = ifp->options->script ? ifp->options->script : UNCONST(SCRIPT); + argv[0] = ifp->options->script; argv[1] = NULL; logdebugx("%s: executing `%s' %s", ifp->name, argv[0], reason);