diff options
-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"); |