changeset 4424:439a039862f7 draft

script: Assign a default script Fixes a dumb mistake I made earlier.
author Roy Marples <roy@marples.name>
date Wed, 10 Apr 2019 21:36:51 +0100
parents 22c551e08f53
children 7cd9fb2bbbe3
files src/if-options.c src/script.c
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/if-options.c	Wed Apr 10 14:10:42 2019 +0100
+++ b/src/if-options.c	Wed Apr 10 21:36:51 2019 +0100
@@ -207,6 +207,8 @@
 	{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 @@
 		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 @@
 		}
 		dl = (size_t)s;
 		if (s == -1 || (ifo->script = malloc(dl)) == NULL) {
+			ifo->script = NULL;
 			logerr(__func__);
 			return -1;
 		}
@@ -2291,6 +2295,7 @@
 	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(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);
--- a/src/script.c	Wed Apr 10 14:10:42 2019 +0100
+++ b/src/script.c	Wed Apr 10 21:36:51 2019 +0100
@@ -718,7 +718,7 @@
 	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);