daemonize: make valgrind happy.
[ccan] / ccan / daemonize / test / run.c
index 9802c44237c5c6da482adfc4bde692933229a61a..c86f214bcae6e3fcfb2901e436971471e21e2479 100644 (file)
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <err.h>
 #include <errno.h>
+#include <string.h>
 
 struct child_data {
        pid_t pid;
@@ -34,6 +35,8 @@ int main(int argc, char *argv[])
                char buffer[2];
                pid = getpid();
                daemonize();
+               /* Keep valgrind happy about uninitialized bytes. */
+               memset(&daemonized, 0, sizeof(daemonized));
                daemonized.pid = getpid();
                daemonized.in_root_dir = (getcwd(buffer, 2) != NULL);
                daemonized.read_from_stdin
@@ -47,7 +50,9 @@ int main(int argc, char *argv[])
                while (getppid() == pid)
                        sleep(1);
                daemonized.ppid = getppid();
-               write(fds[1], &daemonized, sizeof(daemonized));
+               if (write(fds[1], &daemonized, sizeof(daemonized))
+                   != sizeof(daemonized))
+                       exit(1);
                exit(0);
        }