True nohup-like behaviour. Programs ignore to SIGHUP.
authorviric@llimona
Mon, 08 Oct 2007 00:37:16 +0200
changeset 71 c209487034d7
parent 70 51e9b56b487b
child 72 d42f36e87bf3
True nohup-like behaviour. Programs ignore to SIGHUP.
app_term.c
main.h
server.c
signals.c
--- a/app_term.c	Sun Oct 07 23:26:32 2007 +0200
+++ b/app_term.c	Mon Oct 08 00:37:16 2007 +0200
@@ -121,6 +121,8 @@
     switch(pid)
     {
         case 0: /* child */
+            if (command_line.s_param.nohup)
+                ignore_sighup();
             res = dup2(p_child[STDIN], 0);
             if (res == -1) error("Dup2 stdin");
 
--- a/main.h	Sun Oct 07 23:26:32 2007 +0200
+++ b/main.h	Mon Oct 08 00:37:16 2007 +0200
@@ -44,6 +44,7 @@
 void program_timeout(int secs);
 void unprogram_timeout();
 int did_timeout_happen();
+void ignore_sighup();
 
 /* main.c */
 extern int app_stdin;
--- a/server.c	Sun Oct 07 23:26:32 2007 +0200
+++ b/server.c	Mon Oct 08 00:37:16 2007 +0200
@@ -124,6 +124,7 @@
 
     if (command_line.s_param.nohup)
     {
+        ignore_sighup();
         close(0);
         close(1);
         close(2);
--- a/signals.c	Sun Oct 07 23:26:32 2007 +0200
+++ b/signals.c	Mon Oct 08 00:37:16 2007 +0200
@@ -106,3 +106,15 @@
         old_alarm_handler_set = 0;
     }
 }
+
+void ignore_sighup()
+{
+  struct sigaction act;
+
+  act.sa_handler = SIG_IGN;
+  /* Reset the mask */
+  memset(&act.sa_mask,0,sizeof(act.sa_mask));
+  act.sa_flags = 0;
+
+  sigaction(SIGHUP, &act, 0);
+}