mirror of
https://github.com/rsmarples/dhcpcd.git
synced 2024-11-24 10:35:03 +08:00
Add a -C, --nohook option to skip the running of hook scripts. Makes it easier to just not do any configuring of resolv.conf
This commit is contained in:
parent
5f81be76fc
commit
37156a6b53
13
configure.c
13
configure.c
@ -98,6 +98,19 @@ exec_script(const struct options *options, const char *iface,
|
||||
elen += configure_env(env + elen, "new", dhcpn, options);
|
||||
}
|
||||
}
|
||||
/* Add our base environment */
|
||||
if (options->environ) {
|
||||
e = 0;
|
||||
while (options->environ[e++])
|
||||
;
|
||||
env = xrealloc(env, sizeof(char *) * (elen + e + 1));
|
||||
e = 0;
|
||||
while (options->environ[e]) {
|
||||
env[elen + e] = xstrdup(options->environ[e]);
|
||||
e++;
|
||||
}
|
||||
elen += e;
|
||||
}
|
||||
env[elen] = '\0';
|
||||
|
||||
/* OK, we need to block signals */
|
||||
|
@ -266,6 +266,13 @@ Here are some option that deal with turning these bits off.
|
||||
Don't request or claim the address by ARP.
|
||||
.It Fl G , -nogateway
|
||||
Don't set any default routes.
|
||||
.It Ic nohook Ar script
|
||||
Don't run this hook script.
|
||||
Matches full name, or prefixed with 2 numbers optionally ending with .sh.
|
||||
Example for not running the hook script to configure
|
||||
.Pa /etc/resolv.conf :-
|
||||
.Nm
|
||||
-C resolv.conf
|
||||
.It Fl L , -noipv4ll
|
||||
Don't use IPv4LL at all.
|
||||
.It Fl O , -nooption Ar option
|
||||
|
63
dhcpcd.c
63
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
|
||||
|
@ -86,6 +86,13 @@ Don't send any ARP requests.
|
||||
This also disables IPv4LL.
|
||||
.It Ic nogateway
|
||||
Don't install any default routes.
|
||||
.It Ic nohook Ar script
|
||||
Don't run this hook script.
|
||||
Matches full name, or prefixed with 2 numbers optionally ending with .sh.
|
||||
Example for not running the hook script to configure
|
||||
.Pa /etc/resolv.conf :-
|
||||
.Nm dhcpcd
|
||||
-C resolv.conf
|
||||
.It Ic noipv4ll
|
||||
Don't attempt to obtain an IPv4LL address if we failed to get one via DHCP.
|
||||
See
|
||||
|
1
dhcpcd.h
1
dhcpcd.h
@ -87,6 +87,7 @@ struct options {
|
||||
struct in_addr request_address;
|
||||
struct in_addr request_netmask;
|
||||
|
||||
char **environ;
|
||||
const char *script;
|
||||
char pidfile[PATH_MAX];
|
||||
};
|
||||
|
@ -25,6 +25,13 @@ for hook in \
|
||||
@SYSCONFDIR@/dhcpcd.hook \
|
||||
@HOOKDIR@/*
|
||||
do
|
||||
for skip in ${skip_hooks}; do
|
||||
case "${hook}" in
|
||||
"${skip}") continue 2;;
|
||||
*/[0-9][0-9]"-${skip}") continue 2;;
|
||||
*/[0-9][0-9]"-${skip}.sh") continue 2;;
|
||||
esac
|
||||
done
|
||||
if [ -f "${hook}" ]; then
|
||||
. "${hook}"
|
||||
fi
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Just echo our DHCP options we have
|
||||
|
||||
if [ "${reason}" = "TEST" ]; then
|
||||
env | grep "^\(interface\|pid\|reason\)="
|
||||
env | grep "^\(interface\|pid\|reason\|skip_hooks\)="
|
||||
env | grep "^\(new_\|old_\)" | sort
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user