summaryrefslogtreecommitdiffstats
path: root/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-05-20 16:05:15 +0000
committerRoy Marples <roy@marples.name>2008-05-20 16:05:15 +0000
commit37156a6b53681b9ab70482b15358e0a86a08c74d (patch)
treef4adf7b5714d7f1057b16e11507c59dbf49997ce /dhcpcd.c
parent5f81be76fc605333ef92ecde09b093b1ebe5bd4d (diff)
downloaddhcpcd-37156a6b53681b9ab70482b15358e0a86a08c74d.tar.xz
Add a -C, --nohook option to skip the running of hook scripts. Makes it easier to just not do any configuring of resolv.conf
Diffstat (limited to 'dhcpcd.c')
-rw-r--r--dhcpcd.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/dhcpcd.c b/dhcpcd.c
index fd59e84b..059e76cc 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -51,7 +51,7 @@ const char copyright[] = "Copyright (c) 2006-2008 Roy Marples";
/* Don't set any optional arguments here so we retain POSIX
* compatibility with getopt */
-#define OPTS "c:df:h:i:kl:m:no:pr:s:t:u:xADEF:GI:LO:TV"
+#define OPTS "c:df:h:i:kl:m:no:pr:s:t:u:xAC:DEF:GI:LO:TV"
static int doversion = 0;
static int dohelp = 0;
@@ -73,6 +73,7 @@ static const struct option longopts[] = {
{"userclass", required_argument, NULL, 'u'},
{"exit", no_argument, NULL, 'x'},
{"noarp", no_argument, NULL, 'A'},
+ {"nohook", required_argument, NULL, 'C'},
{"duid", no_argument, NULL, 'D'},
{"lastlease", no_argument, NULL, 'E'},
{"fqdn", optional_argument, NULL, 'F'},
@@ -156,7 +157,48 @@ usage(void)
printf("usage: "PACKAGE" [-dknpxADEGHLOSTV] [-c script] [-f file ] [-h hostname]\n"
" [-i classID ] [-l leasetime] [-m metric] [-o option] [-r ipaddr]\n"
" [-s ipaddr] [-t timeout] [-u userclass] [-F none|ptr|both]\n"
- " [-I clientID] <interface>\n");
+ " [-I clientID] [-C hookscript] <interface>\n");
+}
+
+static char *
+add_environ(struct options *options, const char *value, int uniq)
+{
+ char **newlist;
+ char **lst = options->environ;
+ size_t i = 0, l, lv;
+ char *match = NULL, *p;
+
+ match = xstrdup(value);
+ p = strchr(match, '=');
+ if (p)
+ *p++ = '\0';
+ l = strlen(match);
+
+ while (lst && lst[i]) {
+ if (match && strncmp(lst[i], match, l) == 0) {
+ if (uniq) {
+ free(lst[i]);
+ lst[i] = xstrdup(value);
+ } else {
+ /* Append a space and the value to it */
+ l = strlen(lst[i]);
+ lv = strlen(p);
+ lst[i] = xrealloc(lst[i], l + lv + 2);
+ lst[i][l] = ' ';
+ memcpy(lst[i] + l + 1, p, lv);
+ lst[i][l + lv + 2] = '\0';
+ }
+ free(match);
+ return lst[i];
+ }
+ i++;
+ }
+
+ newlist = xrealloc(lst, sizeof(char *) * (i + 2));
+ newlist[i] = xstrdup(value);
+ newlist[i + 1] = NULL;
+ options->environ = newlist;
+ return (newlist[i]);
}
static int
@@ -166,6 +208,7 @@ parse_option(int opt, char *oarg, struct options *options)
int i;
int j;
char *p;
+ size_t s;
switch(opt) {
case 'h':
@@ -282,6 +325,16 @@ parse_option(int opt, char *oarg, struct options *options)
/* IPv4LL requires ARP */
options->options &= ~DHCPCD_IPV4LL;
break;
+ case 'C':
+ /* Commas to spaces for shell */
+ while ((p = strchr(oarg, ',')))
+ *p = ' ';
+ s = strlen("skip_hooks=") + strlen(oarg) + 1;
+ p = xmalloc(sizeof(char) * s);
+ snprintf(p, s, "skip_hooks=%s", oarg);
+ add_environ(options, p, 0);
+ free(p);
+ break;
case 'D':
options->options |= DHCPCD_DUID;
break;
@@ -784,6 +837,12 @@ abort:
close(pidfd);
unlink(options->pidfile);
}
+ if (options->environ) {
+ len = 0;
+ while (options->environ[len])
+ free(options->environ[len++]);
+ free(options->environ);
+ }
free(options);
#ifdef THERE_IS_NO_FORK