From 128aaae36885e55efdd6b1c215071949b1151bb2 Mon Sep 17 00:00:00 2001 From: angt Date: Mon, 23 Nov 2015 12:12:15 +0100 Subject: [PATCH] Add daemon option (only one fork) --- src/main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.c b/src/main.c index d2ce1bc..3df19c7 100644 --- a/src/main.c +++ b/src/main.c @@ -655,6 +655,7 @@ int main (int argc, char **argv) { "multiqueue", NULL, option_option }, { "keepalive", ka_opts, option_option }, { "buffer-size", &buffer_size, option_long }, + { "daemon", NULL, option_option }, { "debug", NULL, option_option }, { "version", NULL, option_option }, { NULL }, @@ -723,6 +724,20 @@ int main (int argc, char **argv) return 1; } + if (option_is_set(opts, "daemon")) { + switch (fork()) { + case -1: + perror("fork"); + return 1; + case 0: + if (setsid()==-1) + perror("setsid"); + break; + default: + _exit(0); + } + } + while (!gt_close) { sock.fd = listener?sk_accept(fd):sk_create(ai, sk_connect);