Add daemon option (only one fork)
This commit is contained in:
15
src/main.c
15
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user