vmrunkernel: allow -M for setting memory start
[akaros.git] / tests / daemonize.c
1 #include <parlib/event.h>
2 #include <parlib/parlib.h>
3 #include <parlib/uthread.h>
4
5 #include <assert.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 static void ev_handler(struct event_msg *msg, unsigned int ev_type, void *data)
10 {
11         int rv;
12
13         assert(msg != NULL);
14         assert(ev_type == EV_USER_IPI);
15         (void)data;
16         rv = msg->ev_arg1;
17         exit(rv);
18 }
19
20 int main(int argc, char *argv[], char *envp[])
21 {
22         struct event_queue *evq, *triggered;
23         pid_t pid;
24         struct event_msg msg;
25
26         register_ev_handler(EV_USER_IPI, ev_handler, 0);
27         evq = get_eventq(EV_MBOX_UCQ);
28         evq->ev_flags |= EVENT_IPI | EVENT_INDIR | EVENT_SPAM_INDIR | EVENT_WAKEUP;
29         register_kevent_q(evq, EV_USER_IPI);
30
31         pid = create_child_with_stdfds(argv[1], argc - 1, argv + 1, envp);
32         if (pid < 0) {
33                 perror("child creation failed");
34                 exit(-1);
35         }
36         sys_proc_run(pid);
37
38         uthread_sleep_forever();
39
40         return -1;
41 }