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" <tytso@mit.edu>
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 <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 @@
 	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 @@
 		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;