From 28d7a25a89c458fcb3851dda2a97fbbc97acc3d7 Mon Sep 17 00:00:00 2001 From: tiptorrent development team Date: Wed, 19 Jan 2022 11:40:40 +0100 Subject: add -d/--daemon option --- src/main.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index fd543a2..5ce629a 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,7 @@ static struct option tip_repo_opts[] = { { "max-clients", 1, 0, 'n' }, { "redirect", 0, 0, 'r' }, { "root", 1, 0, 't' }, + { "daemon", 0, 0, 'd' }, { NULL }, }; @@ -42,7 +43,8 @@ struct ev_io ev_io_server_rest; int main(int argc, char *argv[]) { - int socket_rest, val; + int socket_rest, val, ret; + bool daemon = false; openlog("tiptorrent", LOG_PID, LOG_DAEMON); @@ -52,7 +54,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); while (1) { - val = getopt_long(argc, argv, "n:r", tip_repo_opts, NULL); + val = getopt_long(argc, argv, "n:rd", tip_repo_opts, NULL); if (val < 0) break; @@ -70,6 +72,9 @@ int main(int argc, char *argv[]) case 't': root = strdup(optarg); break; + case 'd': + daemon = true; + break; case '?': return EXIT_FAILURE; default: @@ -77,6 +82,16 @@ int main(int argc, char *argv[]) } } + if (daemon) { + ret = fork(); + if (ret < 0) { + fprintf(stderr, "Failed to fork() daemon tiptorrent\n"); + exit(EXIT_FAILURE); + } else if (ret > 0) { + exit(EXIT_SUCCESS); + } + } + socket_rest = tip_socket_server_init("9999"); if (socket_rest < 0) { syslog(LOG_ERR, "Cannot open tiptorrent server socket\n"); -- cgit v1.2.3-18-g5258