diff options
author | lns <matzeton@googlemail.com> | 2018-04-22 18:58:49 +0200 |
---|---|---|
committer | lns <matzeton@googlemail.com> | 2018-04-22 18:58:49 +0200 |
commit | 10023e21207d9cdd0c299efeca116a1bae6cad1c (patch) | |
tree | 62091f9c6f09979d39274795eeed197f7a5c8e94 /src/main.c | |
parent | 3778cdb66b7a7fc3e6dd43be0bb0da0c5f3f0d7a (diff) |
POTD skeleton #24.
Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -1,8 +1,12 @@ +#include <stdio.h> + #include "log.h" #include "log_colored.h" +#include "utils.h" #include "server.h" #include "server_ssh.h" #include "forward.h" +#include "jail.h" #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -14,7 +18,9 @@ int main(int argc, char *argv[]) const char *ssh_ports[srv_siz]; server_ctx *srv[srv_siz]; forward_ctx *ssh_fwd = NULL; + jail_ctx *jail = NULL; int epoll_fd; + pid_t daemon_pid; (void) argc; (void) argv; @@ -22,6 +28,23 @@ int main(int argc, char *argv[]) LOG_SET_FUNCS_VA(LOG_COLORED_FUNCS); N("%s (C) 2018 Toni Uhlig (%s)", PACKAGE_STRING, PACKAGE_BUGREPORT); + D("%s", "Forking into background/foreground"); + daemon_pid = daemonize(1); + ABORT_ON_FATAL( daemon_pid > 0, "Forking" ); + if (daemon_pid == 0) { + D("Daemon: main child pid: %d", daemon_pid); + } else { + E("Forking failed: %d", daemon_pid); + E_STRERR("Daemonize"); + exit(EXIT_FAILURE); + } + + { + jail_init(&jail, BUFSIZ); + ABORT_ON_FATAL( jail_daemonize(jail), + "Jail daemon startup" ); + } + { ABORT_ON_FATAL( fwd_init_ctx(&ssh_fwd, ssh_init_cb), "Forwarder initialisation" ); |