diff options
author | lns <matzeton@googlemail.com> | 2018-04-26 23:37:17 +0200 |
---|---|---|
committer | lns <matzeton@googlemail.com> | 2018-04-26 23:37:17 +0200 |
commit | 9a00263a93836a1ad36491298df49d151d09554d (patch) | |
tree | 612d15500b91802f202f86b8129acf5e0f4b0783 /src/main.c | |
parent | a2e40e828261e1d8407c1b5c02f715147e568170 (diff) |
POTD skeleton #32.
Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -24,7 +24,7 @@ int main(int argc, char *argv[]) jail_ctx *jail[jail_siz]; forward_ctx *ssh_fwd = NULL; int epoll_fd, proc_status; - pid_t daemon_pid; + pid_t daemon_pid, srv_pid, jail_pid, wpid; (void) argc; (void) argv; @@ -62,8 +62,8 @@ int main(int argc, char *argv[]) epoll_fd = jail_setup_epoll( jail, jail_siz ); D2("Jail epoll fd: %d", epoll_fd); ABORT_ON_FATAL( epoll_fd < 0, "Jail daemon epoll setup" ); - ABORT_ON_FATAL( jail_daemonize(epoll_fd, jail, jail_siz) < 1, - "Jail daemon startup" ); + jail_pid = jail_daemonize(epoll_fd, jail, jail_siz); + ABORT_ON_FATAL( jail_pid < 1, "Jail daemon startup" ); { ABORT_ON_FATAL( fwd_init_ctx(&ssh_fwd, ssh_init_cb), @@ -99,10 +99,19 @@ int main(int argc, char *argv[]) "Server dropping privileges" ); N("%s", "Server epoll mainloop"); - ABORT_ON_FATAL( server_daemonize( epoll_fd, srv, srv_siz ) < 1, - "Server epoll mainloop" ); - - wait(&proc_status); + srv_pid = server_daemonize( epoll_fd, srv, srv_siz ); + ABORT_ON_FATAL( srv_pid < 1, "Server epoll mainloop" ); + + while (1) { + wpid = wait(&proc_status); + if (wpid == jail_pid || + wpid == srv_pid) { + E2("%s daemon with pid %d terminated, exiting", + (wpid == jail_pid ? "Jail" : "Server"), + (wpid == jail_pid ? jail_pid : srv_pid)); + break; + } + } return 0; } |