From: Roy Marples Date: Wed, 7 Oct 2009 21:11:14 +0000 (+0000) Subject: -w, --wait forces dhcpcd to wait for an ip address or timeout when X-Git-Tag: v5.1.2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21090e3d1db2d78644a207b9b34b9264763c2224;p=thirdparty%2Fdhcpcd.git -w, --wait forces dhcpcd to wait for an ip address or timeout when running on more than one interface. --- diff --git a/dhcpcd.8.in b/dhcpcd.8.in index b9697bca..50997a09 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 September 16, 2009 +.Dd October 7, 2009 .Dt DHCPCD 8 SMM .Os .Sh NAME @@ -30,7 +30,7 @@ .Nd an RFC 2131 compliant DHCP client .Sh SYNOPSIS .Nm -.Op Fl bdgknpqABDEGKLTV +.Op Fl bdgknpqwABDEGKLTV .Op Fl c , -script Ar script .Op Fl e , -env Ar value .Op Fl f , -config Ar file @@ -339,6 +339,8 @@ Set the vendor option 03 with an IP address as a string. .D1 dhcpcd \-v 03,\e"192.168.0.2\e" eth0 Set un-encapulated vendor option to hello world. .D1 dhcpcd \-v ,"hello world" eth0 +.It Fl w , -wait +Wait for an address to be assigned before forking to the background. .It Fl x , -exit This will signal an existing .Nm diff --git a/dhcpcd.c b/dhcpcd.c index 875b47e0..7d2d5b12 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -137,7 +137,7 @@ read_pid(void) static void usage(void) { - printf("usage: "PACKAGE" [-dgknpqxyADEGHKLOTV] [-c script] [-f file]" + printf("usage: "PACKAGE" [-dgknpqwxyADEGHKLOTV] [-c script] [-f file]" " [-e var=val]\n" " [-h hostname] [-i classID ] [-l leasetime]" " [-m metric] [-o option]\n" @@ -1545,7 +1545,7 @@ main(int argc, char **argv) { struct if_options *ifo; struct interface *iface; - int opt, oi = 0, signal_fd, sig = 0, i, control_fd; + int opt, oi = 0, signal_fd, sig = 0, i, control_fd, wflag = 0; size_t len; pid_t pid; struct timespec ts; @@ -1581,6 +1581,9 @@ main(int argc, char **argv) case 'n': sig = SIGALRM; break; + case 'w': + wflag = 1; + break; case 'x': sig = SIGTERM; break; @@ -1610,6 +1613,8 @@ main(int argc, char **argv) options |= DHCPCD_TEST | DHCPCD_PERSISTENT; options &= ~DHCPCD_DAEMONISE; } + if (wflag != 0) + options |= DHCPCD_WAITIP; #ifdef THERE_IS_NO_FORK options &= ~DHCPCD_DAEMONISE; @@ -1754,7 +1759,10 @@ main(int argc, char **argv) ifc = argc - optind; ifv = argv + optind; if (options & DHCPCD_BACKGROUND || - (ifc == 0 && options & DHCPCD_LINK && options & DHCPCD_DAEMONISE)) + (ifc == 0 && + options & DHCPCD_LINK && + options & DHCPCD_DAEMONISE && + !(options & DHCPCD_WAITIP))) { daemonise(); } else if (options & DHCPCD_DAEMONISE && ifo->timeout > 0) { diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index a9497889..8a1f94b9 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 September 2, 2009 +.Dd October 7, 2009 .Dt DHCPCD.CONF 5 SMM .Os .Sh NAME @@ -272,6 +272,8 @@ Set un-encapulated vendor option to hello world. .It Ic vendorclassid Ar string Change the default vendorclassid sent from dhcpcd-version. If not set then none is sent. +.It Ic wait +Wait for an address to be assigned before forking to the background. .El .Sh SEE ALSO .Xr dhcpcd-run-hooks 8 , diff --git a/if-options.c b/if-options.c index 53bb1a18..15669d7e 100644 --- a/if-options.c +++ b/if-options.c @@ -72,6 +72,7 @@ const struct option cf_options[] = { {"timeout", required_argument, NULL, 't'}, {"userclass", required_argument, NULL, 'u'}, {"vendor", required_argument, NULL, 'v'}, + {"wait", no_argument, NULL, 'w'}, {"exit", no_argument, NULL, 'x'}, {"allowinterfaces", required_argument, NULL, 'z'}, {"reboot", required_argument, NULL, 'y'}, @@ -329,6 +330,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg) case 'f': /* FALLTHROUGH */ case 'g': /* FALLTHROUGH */ case 'n': /* FALLTHROUGH */ + case 'w': /* FALLTHROUGH */ case 'x': /* FALLTHROUGH */ case 'T': /* We need to handle non interface options */ break; diff --git a/if-options.h b/if-options.h index 0c2818fd..ee40f8a8 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:de:f:gh: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:wxy:z:ABC:DEF:GI:KLN:O:Q:TVW:X:Z:" #define DEFAULT_TIMEOUT 30 #define DEFAULT_REBOOT 10 @@ -70,6 +70,7 @@ #define DHCPCD_QUIET (1 << 21) #define DHCPCD_BACKGROUND (1 << 22) #define DHCPCD_VENDORRAW (1 << 23) +#define DHCPCD_WAITIP (1 << 24) extern const struct option cf_options[];