Re: [PATCH] Don't exec without forking first when calling udevadm.

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

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yeah, ok.

On Thu, 5 Nov 2009, Peter Jones wrote:

Since we don't want init to exit when we call udevadm, fork first.  But
before we do that, may as well wait for our forked udevd to exit, so
there's some chance it's listening for connections.
---
loader/init.c |   39 ++++++++++++++++++++++++++++++++-------
1 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/loader/init.c b/loader/init.c
index 1b8c858..1505657 100644
--- a/loader/init.c
+++ b/loader/init.c
@@ -584,17 +584,42 @@ int main(int argc, char **argv) {

    printf("creating /dev filesystem... ");
    if (!testing) {
+        pid_t childpid;
        if (mount("/dev", "/dev", "tmpfs", 0, NULL))
            fatal_error(1);
        createDevices();
        printf("done\n");
-	printf("starting udev...");
-	if (fork() == 0) {
-	    execl("/sbin/udevd", "/sbin/udevd","--daemon",NULL);
-	    exit(1);
-	}
-
-        execl("/sbin/udevadm", "udevadm", "control", "--env=ANACONDA=1", NULL);
+        printf("starting udev...");
+        if ((childpid = fork()) == 0) {
+            execl("/sbin/udevd", "/sbin/udevd", "--daemon", NULL);
+            exit(1);
+        }
+
+        /* wait at least until the udevd process that we forked exits */
+        do {
+            pid_t retpid;
+            int waitstatus;
+
+            retpid = waitpid(childpid, &waitstatus, 0);
+            if (retpid == -1) {
+                if (errno == EINTR)
+                    continue;
+                /* if the child exited before we called waitpid, we can get
+                 * ECHILD without anything really being wrong; we just lost
+                 * the race.*/
+                if (errno == ECHILD)
+                    break;
+                printf("init: error waiting on udevd: %m\n");
+                exit(1);
+            } else if (WIFEXITED(waitstatus)) {
+                break;
+            }
+        } while (1);
+
+        if (fork() == 0) {
+            execl("/sbin/udevadm", "udevadm", "control", "--env=ANACONDA=1", NULL);
+            exit(1);
+        }
    }
    printf("done\n");



- -- David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkrzVV8ACgkQ5hsjjIy1VknrRQCg0J4gNSZfrG0Yzqc8rksgi9xc
zvQAn3Pj4/bYniXKU1SLYR0ATQBjWd3v
=418l
-----END PGP SIGNATURE-----

_______________________________________________
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