From: Roy Marples Date: Sat, 25 Jul 2009 23:30:08 +0000 (+0000) Subject: -e, --env var=value X-Git-Tag: v5.0.7~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=685f6a7778f276746e6b0bb449b9bde32b9ba269;p=thirdparty%2Fdhcpcd.git -e, --env var=value now pushes var=value to the environment when dhcpcd-run-hooks is run. This allows the possibility to set env vars that hook scripts can work off. A good example of this is 30-hostname so that force_hostname=YES can set the hostname regardless of the current hostname. --reconfigure now takes the short option -g. --- diff --git a/dhcpcd-hooks/30-hostname b/dhcpcd-hooks/30-hostname index 4fae4b50..a19fc0df 100644 --- a/dhcpcd-hooks/30-hostname +++ b/dhcpcd-hooks/30-hostname @@ -2,7 +2,13 @@ need_hostname() { - case "$(hostname)" in + local hostname="" + + case "$force_hostname" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) ;; + *) hostname="$(hostname)";; + esac + case "$hostname" in ""|"(none)"|localhost|localhost.localdomain) [ -n "$new_host_name" -o -n "$new_fqdn_name" ];; "$old_host_name"|"$old_fqdn_name") diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 1f284a08..d0743b0e 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 25, 2009 +.Dd July 26, 2009 .Dt DHCPCD 8 SMM .Os .Sh NAME @@ -30,8 +30,9 @@ .Nd an RFC 2131 compliant DHCP client .Sh SYNOPSIS .Nm -.Op Fl bdeknpqABDEGKLTV +.Op Fl bdgknpqABDEGKLTV .Op Fl c , -script Ar script +.Op Fl e , -env Ar value .Op Fl f , -config Ar file .Op Fl h , -hostname Ar hostname .Op Fl i , -vendorclassid Ar vendorclassid @@ -80,7 +81,9 @@ then runs the configuration script which writes DNS information to .Xr resolvconf 8 , if available, otherwise directly to .Pa /etc/resolv.conf . -If the hostname is currenly blank, (null) or localhost then +If the hostname is currenly blank, (null) or localhost, or +.Va force_hostname +is YES or TRUE or 1 then .Nm sets the hostname to the one supplied by the DHCP server. .Nm @@ -171,7 +174,15 @@ Echo debug messages to the stderr and syslog. Subsequent debug options stop .Nm from daemonising. -.It Fl e , -reconfigure +.It Fl e , -env Ar value +Push +.Ar value +to the environment for use in +.Xr dhcpcd-run-hooks 8 . +For example, you can force the hostname hook to always set the hostname with +.Fl e +.Va force_hostname=YES . +.It Fl g , -reconfigure .Nm will re-apply IP address, routing and run .Xr dhcpcd-run-hooks 8 diff --git a/dhcpcd.c b/dhcpcd.c index b5cb9718..f2a66890 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1467,7 +1467,7 @@ handle_args(struct fd_list *fd, int argc, char **argv) while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1) { switch (opt) { - case 'e': + case 'g': do_reconf = 1; break; case 'k': @@ -1563,12 +1563,12 @@ main(int argc, char **argv) while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1) { switch (opt) { - case 'e': - sig = SIGUSR1; - break; case 'f': cffile = optarg; break; + case 'g': + sig = SIGUSR1; + break; case 'k': sig = SIGHUP; break; diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index a605ef8b..05b29927 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 25, 2009 +.Dd July 26, 2009 .Dt DHCPCD.CONF 5 SMM .Os .Sh NAME @@ -83,6 +83,14 @@ Only accept packets from is ignored if .Ic whitelist is set. +.It Ic env Ar value +Push +.Ar value +to the environment for use in +.Xr dhcpcd-run-hooks 8 . +For example, you can force the hostname hook to always set the hostname with +.Ic env +.Va force_hostname=YES . .It Ic clientid Ar string Send the .Ar clientid . diff --git a/if-options.c b/if-options.c index a22929b3..7d30ac6c 100644 --- a/if-options.c +++ b/if-options.c @@ -55,8 +55,9 @@ const struct option cf_options[] = { {"background", no_argument, NULL, 'b'}, {"script", required_argument, NULL, 'c'}, {"debug", no_argument, NULL, 'd'}, - {"reconfigure", no_argument, NULL, 'e'}, + {"env", required_argument, NULL, 'e'}, {"config", required_argument, NULL, 'f'}, + {"reconfigure", no_argument, NULL, 'g'}, {"hostname", optional_argument, NULL, 'h'}, {"vendorclassid", optional_argument, NULL, 'i'}, {"release", no_argument, NULL, 'k'}, @@ -319,7 +320,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg) struct rt *rt; switch(opt) { - case 'e': /* FALLTHROUGH */ + case 'g': /* FALLTHROUGH */ case 'n': /* FALLTHROUGH */ case 'x': /* FALLTHROUGH */ case 'T': /* We need to handle non interface options */ @@ -333,6 +334,9 @@ parse_option(struct if_options *ifo, int opt, const char *arg) case 'd': ifo->options |= DHCPCD_DEBUG; break; + case 'e': + add_environ(ifo, arg, 1); + break; case 'h': if (arg) { s = parse_string(ifo->hostname, diff --git a/if-options.h b/if-options.h index 3fa86396..46534ea7 100644 --- a/if-options.h +++ b/if-options.h @@ -37,7 +37,7 @@ /* Don't set any optional arguments here so we retain POSIX * compatibility with getopt */ -#define IF_OPTS "bc:def:h:i:kl:m:no:pqr:s:t:u:v:xy:z:ABC:DEF:GI:KLN:O:Q:TVW:X:Z:" +#define IF_OPTS "bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:xy:z:ABC:DEF:GI:KLN:O:Q:TVW:X:Z:" #define DEFAULT_TIMEOUT 30 #define DEFAULT_REBOOT 10