8 #include <process/process.h>
9 #include <waiter/waiter.h>
10 #include <talloc/talloc.h>
12 static const char *async_fifo = "/tmp/test-process-both.fifo";
14 static int do_sync_child(void)
19 static int do_async_child(void)
24 fd = open(async_fifo, O_RDONLY);
36 struct process *sync_process;
37 struct process *async_process;
40 int async_exit_status;
44 static void async_exit_cb(struct process *process)
46 struct test *test = process->data;
47 test->async_exited = true;
48 test->async_exit_status = process->exit_status;
51 int main(int argc, char **argv)
53 const char *sync_child_argv[3], *async_child_argv[3];
54 struct waitset *waitset;
59 if (argc == 2 && !strcmp(argv[1], "sync-child"))
60 return do_sync_child();
62 if (argc == 2 && !strcmp(argv[1], "async-child"))
63 return do_async_child();
65 test = talloc_zero(NULL, struct test);
68 rc = mkfifo(async_fifo, 0600);
71 waitset = waitset_create(test);
73 process_init(test, waitset, false);
75 sync_child_argv[0] = argv[0];
76 sync_child_argv[1] = "sync-child";
77 sync_child_argv[2] = NULL;
79 test->sync_process = process_create(test);
80 test->sync_process->path = sync_child_argv[0];
81 test->sync_process->argv = sync_child_argv;
83 async_child_argv[0] = argv[0];
84 async_child_argv[1] = "async-child";
85 async_child_argv[2] = NULL;
87 test->async_process = process_create(test);
88 test->async_process->path = async_child_argv[0];
89 test->async_process->argv = async_child_argv;
90 test->async_process->exit_cb = async_exit_cb;
91 test->async_process->data = test;
93 process_run_async(test->async_process);
95 process_run_sync(test->sync_process);
97 assert(WIFEXITED(test->sync_process->exit_status));
98 assert(WEXITSTATUS(test->sync_process->exit_status) == 42);
100 /* now that the sync process has completed, let the async process
102 test->async_fd = open(async_fifo, O_WRONLY);
103 assert(test->async_fd >= 0);
105 write(test->async_fd, &c, 1);
108 waiter_poll(waitset);
110 if (test->async_exited)
114 assert(WIFEXITED(test->async_exit_status));
115 assert(WEXITSTATUS(test->async_exit_status) == 43);