PATCH [5/5]: mkinitrd: fix dhclient invocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

And the last one, makes dhcp config actually work.

Regards,

Hans
diff -up mkinitrd-6.0.75/nash/network.c.dhcp mkinitrd-6.0.75/nash/network.c
--- mkinitrd-6.0.75/nash/network.c.dhcp	2009-01-31 13:19:54.000000000 +0100
+++ mkinitrd-6.0.75/nash/network.c	2009-01-31 13:21:46.000000000 +0100
@@ -60,6 +60,7 @@
 #define DHCLIENT       "/sbin/dhclient"
 #define RESOLVCONF     "/etc/resolv.conf"
 #define DHCLIENTLEASES "/var/lib/dhclient/dhclient.leases"
+#define DHCLIENTPID    "/var/run/dhclient.pid"
 #define BUFSIZ         4096
 
 /* returns 1 for link, 0 for no link, -1 for unknown */
@@ -454,24 +455,40 @@ int nashNetworkCommand(char * cmd) {
 
         /* start dhclient */
         if (pid == 0) {
-            /* dhclient returns code 2 for failure, do the same */
+            /* dhclient returns code 2 for failure, use a different code to
+               signal we never actually managed to start dhclient */
             if (setpgrp() == -1)
-                exit(2);
+                exit(3);
 
-            if (execl(DHCLIENT, DHCLIENT, "-4", "-1", "-n", NULL) == -1)
-                exit(2);
+            if (execl(DHCLIENT, DHCLIENT, "-1", "-sf", "/dev/null", dev, NULL) == -1)
+                exit(3);
         } else if (pid == -1) {
-            eprintf("Failed to start dhclient.\n");
+            eprintf("Failed to fork to start dhclient: %m\n");
             return 1;
         } else {
             if (waitpid(pid, &status, 0) == -1) {
+                eprintf("waitpid() for dhclient failed: %m\n");
+                return 1;
+            }
+            if (!WIFEXITED(status)) {
+                eprintf("dhclient did not exit normally\n");
+                return 1;
+            }
+            if (WEXITSTATUS(status) != 0) {
+                if (WEXITSTATUS(status) == 2)
+                    eprintf("Could not get a dhcp lease\n");
+                else
+                    eprintf("dhclient abnormal exit status: %d\n",
+                            WEXITSTATUS(status));
                 return 1;
             }
         }
 
         /* collect lease information */
-        if ((f = fopen(DHCLIENTLEASES, "r")) == NULL)
+        if ((f = fopen(DHCLIENTLEASES, "r")) == NULL) {
+            eprintf("Failed to open %s: %m\n", DHCLIENTLEASES);
             return 1;
+        }
 
         while (fgets(linebuf, BUFSIZ, f) != NULL) {
             linebuf[strlen(linebuf) - 1] = '\0';
@@ -529,6 +546,15 @@ int nashNetworkCommand(char * cmd) {
 
         fclose(f);
 
+        /* Kill the background dhclient process */
+        if ((f = fopen(DHCLIENTPID, "r"))) {
+            if(fgets(linebuf, BUFSIZ, f)) {
+                pid = strtol(linebuf, NULL, 10);
+                kill(pid, SIGTERM);
+            }
+            fclose(f);
+        }
+
         if (hostname)
             nashSetHostname(hostname, domain);
     }
diff -up mkinitrd-6.0.75/mkinitrd~ mkinitrd-6.0.75/mkinitrd
--- mkinitrd-6.0.75/mkinitrd~	2009-01-31 15:58:36.000000000 +0100
+++ mkinitrd-6.0.75/mkinitrd	2009-01-31 15:58:36.000000000 +0100
@@ -721,8 +721,12 @@ handlenetdev() {
     fi
     network="network --device $dev --bootproto $BOOTPROTO $IPSTR"
     if [ "$BOOTPROTO" = "dhcp" ]; then
+        if [ ! -f  "$MNTIMAGE/sbin/dhclient" ]; then
+            inst "/sbin/dhclient" "$MNTIMAGE" /sbin/dhclient
+            mkdir -p $MNTIMAGE/var/lib/dhclient
+            mkdir -p $MNTIMAGE/var/run
+        fi
         dhclient_leases_cmd="cp /var/lib/dhclient/dhclient.leases /sysroot/dev/.dhclient-$dev.leases"
-        mkdir -p $MNTIMAGE/var/lib/dhclient
     fi
 }
 
@@ -1374,7 +1378,6 @@ if [ -n "$raiddevices" ]; then
 fi
 
 if [ "$root" == "dhcp" ]; then
-    inst "/sbin/dhclient" "$MNTIMAGE" /sbin/dhclient
     inst "/usr/sbin/nbd-client" "$MNTIMAGE" /sbin/nbd-client
 fi
 
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux