]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libuuid: When starting uuidd, use waitpid() to reap the zombie process
authorTheodore Ts'o <tytso@mit.edu>
Mon, 17 Dec 2007 20:16:44 +0000 (15:16 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 17 Dec 2007 20:16:44 +0000 (15:16 -0500)
The uuidd process will fork and let the parent process exit to create
the daemon.  So use waitpid to reap the zombie, as well as using it to
time when it is safe to try to connect to the daemon.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/uuid/gen_uuid.c

index a84ae1c8d22887e8ca1be83793c2d36f8912b930..1918b3bff9c7410cf2a245655ccd154080b31cc3 100644 (file)
@@ -50,6 +50,7 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <sys/wait.h>
 #include <sys/stat.h>
 #include <sys/file.h>
 #ifdef HAVE_SYS_IOCTL_H
@@ -390,6 +391,7 @@ static int get_uuid_via_daemon(int op, uuid_t out, int *num)
        ssize_t ret;
        int32_t reply_len = 0, expected = 16;
        struct sockaddr_un srv_addr;
+       pid_t pid;
        static const char *uuidd_path = UUIDD_PATH;
        static int access_ret = -2;
 
@@ -404,11 +406,11 @@ static int get_uuid_via_daemon(int op, uuid_t out, int *num)
                if (access_ret == -2)
                        access_ret = access(uuidd_path, X_OK);
                if (access_ret == 0) {
-                       if (fork() == 0) {
+                       if ((pid = fork()) == 0) {
                                execl(uuidd_path, "uuidd", "-qT", "300", 0);
                                exit(1);
                        }
-                       usleep(500);
+                       (void) waitpid(pid, 0, 0);
                        if (connect(s, (const struct sockaddr *) &srv_addr,
                                    sizeof(struct sockaddr_un)) < 0)
                                goto fail;