I very much appreciate the work of reyk@ on dhclient to make it renew the lease 
when the
link is lost. However it might happen that you don't have a link at the moment 
where
you launch dhclient but you know that you might get a link afterwards.
This is true when you launch your laptop somewhere where you have wifi 
connectivity
but unfortunately you're in a spot where you don't currently receive it.
If you specify 'dhcp' in hostname.<if> you will have to wait until dhclient 
times out
or hit Ctrl-C at startup.
This tiny patch adds an option to dhclient to tell it to just go into 
background and wait
until you get a link.

I would appreciate any comments.
Thanks!


Index: dhclient.c
===================================================================
RCS file: /cvs/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.118
diff -u -r1.118 dhclient.c
--- dhclient.c  9 May 2008 05:19:14 -0000       1.118
+++ dhclient.c  18 May 2008 15:11:53 -0000
@@ -253,7 +253,7 @@
 int
 main(int argc, char *argv[])
 {
-       int      ch, fd, quiet = 0, i = 0, pipe_fd[2];
+       int      ch, fd, quiet = 0, background = 0, i = 0, pipe_fd[2];
        extern char *__progname;
        struct passwd *pw;
 
@@ -261,8 +261,11 @@
        openlog(__progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY);
        setlogmask(LOG_UPTO(LOG_INFO));
 
-       while ((ch = getopt(argc, argv, "c:dl:qu")) != -1)
+       while ((ch = getopt(argc, argv, "bc:dl:qu")) != -1)
                switch (ch) {
+               case 'b':
+                       background = 1;
+                       break;
                case 'c':
                        path_dhclient_conf = optarg;
                        break;
@@ -319,6 +322,9 @@
 
        read_client_conf();
 
+       if (background)
+               goto dispatch; 
+
        if (!(ifi->linkstat = interface_link_status(ifi->name))) {
                fprintf(stderr, "%s: no link ...", ifi->name);
                if (config->link_timeout == 0) {
@@ -409,7 +415,7 @@
 {
        extern char     *__progname;
 
-       fprintf(stderr, "usage: %s [-dqu] [-c file] [-l file] interface\n",
+       fprintf(stderr, "usage: %s [-bdqu] [-c file] [-l file] interface\n",
            __progname);
        exit(1);
 }

Reply via email to