]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
script: Assign a default script
authorRoy Marples <roy@marples.name>
Wed, 10 Apr 2019 20:36:51 +0000 (21:36 +0100)
committerRoy Marples <roy@marples.name>
Wed, 10 Apr 2019 20:36:51 +0000 (21:36 +0100)
Fixes a dumb mistake I made earlier.

src/if-options.c
src/script.c

index dee07eb11874ea68a3908aa3f585ecd96a7ec304..c70d18a14ea5d52e56b1ba9a1c78e50091ad7d44 100644 (file)
@@ -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);
index deeda5272e355fa45fadd11e6e470d2119411bb5..451b0308059e14b90d16c68f307cd3459cf2e4ab 100644 (file)
@@ -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);