diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2022-01-19 11:40:40 +0100 |
---|---|---|
committer | tiptorrent development team <tiptorrent@soleta.eu> | 2022-01-19 11:45:04 +0100 |
commit | 28d7a25a89c458fcb3851dda2a97fbbc97acc3d7 (patch) | |
tree | 3cf0db734f301274075d5c9c2fb047f4a0b7e63e /src | |
parent | 298f9da0de30a6cd9652d71cd5e529fb5d925c89 (diff) |
add -d/--daemon option
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -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"); |