142924bdf73f — pouya@nohup.io tip 10 months ago
Daemonise first
1 files changed, 6 insertions(+), 6 deletions(-)

M main.c
M main.c +6 -6
@@ 152,18 152,18 @@ main(int argc, char** argv) {
 		cleanup();
 	}
 
+	if(ctxt.daemon) if(daemon(0, 0)) {
+		perror("cannot create daemon");
+		ctxt.error = E_SYS;
+		cleanup();
+	}
+
 	if(signal(SIGINT, &cleanup) == SIG_IGN)
 		signal(SIGINT, SIG_IGN);
 	if(signal(SIGHUP, &cleanup) == SIG_IGN)
 		signal(SIGHUP, SIG_IGN);
 	if(signal(SIGTERM, &cleanup) == SIG_IGN)
 		signal(SIGTERM, SIG_IGN);
-
-	if(ctxt.daemon) if(daemon(0, 0)) {
-		perror("cannot create daemon");
-		ctxt.error = E_SYS;
-		cleanup();
-	}
  
 	while(1) if((ctxt.cfd = cliaccpt(ctxt.sfd)) >= 0) {
 		srv(ctxt.cfd);