Returns now GNUNET_SYSERR
[oweals/gnunet.git] / src / util / signal.c
index 478551ca28d535dc150df4249d516420729c3dcd..0fe4bfc96e6a1cac3ea8f505b0072090ec4c4138 100644 (file)
@@ -39,8 +39,12 @@ struct GNUNET_SIGNAL_Context
 #endif
 };
 
+#ifdef WINDOWS
+GNUNET_SIGNAL_Handler w32_sigchld_handler = NULL;
+#endif
+
 struct GNUNET_SIGNAL_Context *
-GNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler)
+GNUNET_SIGNAL_handler_install (int signum, GNUNET_SIGNAL_Handler handler)
 {
   struct GNUNET_SIGNAL_Context *ret;
 #ifndef MINGW
@@ -48,7 +52,7 @@ GNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler)
 #endif
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_SIGNAL_Context));
-  ret->sig = signal;
+  ret->sig = signum;
   ret->method = handler;
 #ifndef MINGW
   sig.sa_handler = (void *) handler;
@@ -58,7 +62,21 @@ GNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler)
 #else
   sig.sa_flags = SA_RESTART;
 #endif
-  sigaction (signal, &sig, &ret->oldsig);
+  sigaction (signum, &sig, &ret->oldsig);
+#else
+  if (signum == GNUNET_SIGCHLD)
+    w32_sigchld_handler = handler;
+  else
+    {
+      __p_sig_fn_t sigret = signal (signum, (__p_sig_fn_t) handler);
+      if (sigret == SIG_ERR)
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              _
+              ("signal (%d, %p) returned %d.\n"),
+              signum, handler, sigret);
+        }
+    }
 #endif
   return ret;
 }