Add daemon option (only one fork)

This commit is contained in:
angt
2015-11-23 12:12:15 +01:00
parent 230c9fa26a
commit 128aaae368

View File

@@ -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);