1 #include <ccan/daemonize/daemonize.h>
2 #include <ccan/daemonize/daemonize.c>
3 #include <ccan/tap/tap.h>
13 int read_from_stdin, write_to_stdout, write_to_stderr;
16 int main(int argc, char *argv[])
19 struct child_data daemonized;
25 err(1, "Failed pipe");
27 /* Since daemonize forks and parent exits, we need to fork
31 err(1, "Failed fork");
37 daemonized.pid = getpid();
38 daemonized.in_root_dir = (getcwd(buffer, 2) != NULL);
39 daemonized.read_from_stdin
40 = read(STDIN_FILENO, buffer, 1) == -1 ? errno : 0;
41 daemonized.write_to_stdout
42 = write(STDOUT_FILENO, buffer, 1) == -1 ? errno : 0;
43 daemonized.write_to_stderr
44 = write(STDERR_FILENO, buffer, 1) == -1 ? errno : 0;
46 /* Make sure parent exits. */
47 while (getppid() == pid)
49 daemonized.ppid = getppid();
50 if (write(fds[1], &daemonized, sizeof(daemonized))
51 != sizeof(daemonized))
56 if (read(fds[0], &daemonized, sizeof(daemonized)) != sizeof(daemonized))
57 err(1, "Failed read");
59 ok1(daemonized.pid != pid);
60 ok1(daemonized.ppid == 1);
61 ok1(daemonized.in_root_dir);
62 ok1(daemonized.read_from_stdin == EBADF);
63 ok1(daemonized.write_to_stdout == EBADF);
64 ok1(daemonized.write_to_stderr == EBADF);