]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
-e, --env var=value
authorRoy Marples <roy@marples.name>
Sat, 25 Jul 2009 23:30:08 +0000 (23:30 +0000)
committerRoy Marples <roy@marples.name>
Sat, 25 Jul 2009 23:30:08 +0000 (23:30 +0000)
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.

dhcpcd-hooks/30-hostname
dhcpcd.8.in
dhcpcd.c
dhcpcd.conf.5.in
if-options.c
if-options.h

index 4fae4b508854c58e3d0f8ae1f11b3d0965e4fd43..a19fc0df5526a8bdac18e773ead1cdb8a9475822 100644 (file)
@@ -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")
index 1f284a0854f100484068385875c02a26066cee11..d0743b0e8398d08b20e5418ecada0d29ba78c769 100644 (file)
@@ -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
index b5cb9718d9e02ec114d024effa0942efcdee5528..f2a668909f69027e67f91bf46ebaeeb73604a8b3 100644 (file)
--- 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;
index a605ef8b0f8eff3fc13cadc84257a19584cb11a8..05b299277516111a8ae1ce70dc4390762dfd64d4 100644 (file)
@@ -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 .
index a22929b358602f8408c8534d89ab0c5946a6b76d..7d30ac6c48d84d9f27b081a8130bafb3c13c80b5 100644 (file)
@@ -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,
index 3fa86396ac3cb3847cc72c9af10e289cbfbcf384..46534ea74398ff08fa125d9b5838389b44839e49 100644 (file)
@@ -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