Mercurial > hg > dhcpcd
changeset 1369:997892155586 draft
-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.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Sat, 25 Jul 2009 23:30:08 +0000 |
| parents | 05a688b7b423 |
| children | bf8a3471cc6a |
| files | dhcpcd-hooks/30-hostname dhcpcd.8.in dhcpcd.c dhcpcd.conf.5.in if-options.c if-options.h |
| diffstat | 6 files changed, 42 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/dhcpcd-hooks/30-hostname Sat Jul 25 23:29:47 2009 +0000 +++ b/dhcpcd-hooks/30-hostname Sat Jul 25 23:30:08 2009 +0000 @@ -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")
--- a/dhcpcd.8.in Sat Jul 25 23:29:47 2009 +0000 +++ b/dhcpcd.8.in Sat Jul 25 23:30:08 2009 +0000 @@ -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 @@ .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 @@ 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
--- a/dhcpcd.c Sat Jul 25 23:29:47 2009 +0000 +++ b/dhcpcd.c Sat Jul 25 23:30:08 2009 +0000 @@ -1467,7 +1467,7 @@ 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 @@ 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;
--- a/dhcpcd.conf.5.in Sat Jul 25 23:29:47 2009 +0000 +++ b/dhcpcd.conf.5.in Sat Jul 25 23:30:08 2009 +0000 @@ -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 @@ 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 .
--- a/if-options.c Sat Jul 25 23:29:47 2009 +0000 +++ b/if-options.c Sat Jul 25 23:30:08 2009 +0000 @@ -55,8 +55,9 @@ {"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 @@ 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 @@ case 'd': ifo->options |= DHCPCD_DEBUG; break; + case 'e': + add_environ(ifo, arg, 1); + break; case 'h': if (arg) { s = parse_string(ifo->hostname,
--- a/if-options.h Sat Jul 25 23:29:47 2009 +0000 +++ b/if-options.h Sat Jul 25 23:30:08 2009 +0000 @@ -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
