From 9d8c203a462ee18c1fd09a68cfe0e2ec7d8288da Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 17 Dec 2007 15:16:44 -0500 Subject: [PATCH] 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" --- lib/uuid/gen_uuid.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; -- 1.8.3.1