From: Theodore Ts'o Date: Mon, 17 Dec 2007 20:16:44 +0000 (-0500) Subject: libuuid: When starting uuidd, use waitpid() to reap the zombie process X-Git-Tag: v1.40.4~19 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=9d8c203a462ee18c1fd09a68cfe0e2ec7d8288da;p=tools%2Fe2fsprogs.git libuuid: When starting uuidd, use waitpid() to reap the zombie process 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" --- diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c index a84ae1c..1918b3b 100644 --- a/lib/uuid/gen_uuid.c +++ b/lib/uuid/gen_uuid.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #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;