Sistemati alcuni nomi, l'inserimento dell'indice analitico e della
[gapil.git] / sources / SigHand.c
index b5d6c7bda49de7c003e7cdf80bf2dd83b38212e6..605493d1f2f6779c7200f589e125658c2f98cc64 100644 (file)
  *
  * Author: S. Piccardi Dec. 2002
  *
- * $Id: SigHand.c,v 1.7 2003/05/06 14:05:12 piccardi Exp $
- *
  *****************************************************************************/
-#include <errno.h>                               /* error simbol definitions */
-#include <stdio.h>                                 /* standard I/O functions */
-#include <signal.h>                          /* signal handling declarations */
-#include <sys/types.h>
-#include <sys/wait.h>
+#include <errno.h>       /* error definitions and routines */
+#include <stdio.h>      /* standard I/O library */
+#include <signal.h>      /* signal constants, types and functions */
+#include <sys/types.h>   /* primitive system data types */
+#include <sys/wait.h>   /* process termination constants and functions */
 
 #include "Gapil.h"
 #include "macros.h"
  * Initialize a signal handler.
  * To enable the signal handling a process we need to tell it to
  * kernel; this is done writing all needed info to a sigaction structure
- * named sigact, and then callind sigaction() system call passing the
+ * named sigact, and then calling sigaction() system call passing the
  * information stored in the sigact structure variable.
  *
  * Input:  the signal to handle 
  *         the signal handler function
- * Return: the previous sigaction structure
+ * Return: the previous signal handler
  */
-inline SigFunc * Signal(int signo, SigFunc *func) 
+inline SigHandler * Signal(int signo, SigHandler *func) 
 {
     struct sigaction new_handl, old_handl;
+    new_handl.sa_flags=0;                    /* init to 0 all flags */
     new_handl.sa_handler = func;             /* set signal handler */
     /* clear signal mask: no signal blocked during execution of func */
     if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */
         return SIG_ERR;
     }
-    new_handl.sa_flags=0;                    /* init to 0 all flags */
     /* change action for signo signal */
     if (sigaction(signo, &new_handl, &old_handl)){ 
         return SIG_ERR;
@@ -67,19 +65,19 @@ inline SigFunc * Signal(int signo, SigFunc *func)
  * Initialize a signal handler.
  * To enable the signal handling a process we need to tell it to
  * kernel; this is done writing all needed info to a sigaction structure
- * named sigact, and then callind sigaction() system call passing the
+ * named sigact, and then calling sigaction() system call passing the
  * information stored in the sigact structure variable.
  * This version enable BSD semantics with SA_RESTART
  *
  * Input:  the signal to handle 
  *         the signal handler function
- * Return: the previous sigaction structure
+ * Return: the previous signal handler
  */
-inline SigFunc * SignalRestart(int signo, SigFunc *func) 
+inline SigHandler * SignalRestart(int signo, SigHandler *func) 
 {
     struct sigaction new_handl, old_handl;
-    new_handl.sa_handler = func;             /* set signal handler */
     new_handl.sa_flags = SA_RESTART;         /* restart system call */
+    new_handl.sa_handler = func;             /* set signal handler */
     /* clear signal mask: no signal blocked during execution of func */
     if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */
         return SIG_ERR;
@@ -91,13 +89,66 @@ inline SigFunc * SignalRestart(int signo, SigFunc *func)
     return (old_handl.sa_handler);
 }
 
+/*
+ * Function Action
+ * Initialize a sa_sigaction signal handler.
+ * To enable the signal handling a process we need to tell it to
+ * kernel; this is done writing all needed info to a sigaction structure
+ * named sigact, and then calling sigaction() system call passing the
+ * information stored in the sigact structure variable.
+ *
+ * Input:  the signal to handle 
+ *         the signal handler function (sa_sigaction type)
+ * Return: the previous signal handler
+ */
+inline SigAction * Action(int signo, SigAction *func) 
+{
+    struct sigaction new_handl, old_handl;
+    new_handl.sa_flags=SA_SIGINFO;           /* we use sa_sigaction handler */
+    new_handl.sa_sigaction = func;           /* set signal handler */
+    /* clear signal mask: no signal blocked during execution of func */
+    if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */
+        return NULL;
+    }
+    /* change action for signo signal */
+    if (sigaction(signo, &new_handl, &old_handl)){ 
+        return NULL;
+    }
+    return (old_handl.sa_sigaction);
+}
+/*
+ * Function Action
+ * Initialize a sa_sigaction signal handler.
+ * To enable the signal handling a process we need to tell it to
+ * kernel; this is done writing all needed info to a sigaction structure
+ * named sigact, and then calling sigaction() system call passing the
+ * information stored in the sigact structure variable.
+ *
+ * Input:  the signal to handle 
+ *         the signal handler function (sa_sigaction type)
+ * Return: the previous signal handler
+ */
+inline SigAction * ActionRestart(int signo, SigAction *func) 
+{
+    struct sigaction new_handl, old_handl;
+    new_handl.sa_flags=SA_SIGINFO|SA_RESTART;/* flag setup */
+    new_handl.sa_sigaction = func;           /* set signal handler */
+    /* clear signal mask: no signal blocked during execution of func */
+    if (sigemptyset(&new_handl.sa_mask)!=0){ /* initialize signal set */
+        return NULL;
+    }
+    /* change action for signo signal */
+    if (sigaction(signo, &new_handl, &old_handl)){ 
+        return NULL;
+    }
+    return (old_handl.sa_sigaction);
+}
 
 /* 
  * Functions: HandSigCHLD
- * Generic handler for SIGCHLD signal
+ * Generic simple handler for SIGCHLD signal
  * 
  * Simone Piccardi Dec. 2002
- * $Id: SigHand.c,v 1.7 2003/05/06 14:05:12 piccardi Exp $
  */
 void HandSigCHLD(int sig)
 {