Sfoglia il codice sorgente

BUnixSignal: don't provide any information about a signal other than the signal number. This is because multiple signals (at least SIGCHLD) may be merged into one, so it
is useless to provide additional info about a signal.

ambrop7 15 anni fa
parent
commit
8e73c9d4b3
5 ha cambiato i file con 19 aggiunte e 12 eliminazioni
  1. 2 2
      system/BProcess.c
  2. 2 2
      system/BSignal.c
  3. 4 0
      system/BSignal.h
  4. 1 2
      system/BUnixSignal.c
  5. 10 6
      system/BUnixSignal.h

+ 2 - 2
system/BProcess.c

@@ -116,9 +116,9 @@ static void wait_job_handler (BProcessManager *o)
     return;
     return;
 }
 }
 
 
-static void signal_handler (BProcessManager *o, struct BUnixSignal_siginfo siginfo)
+static void signal_handler (BProcessManager *o, int signo)
 {
 {
-    ASSERT(siginfo.signo == SIGCHLD)
+    ASSERT(signo == SIGCHLD)
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&o->d_obj);
     
     
     work_signals(o);
     work_signals(o);

+ 2 - 2
system/BSignal.c

@@ -84,9 +84,9 @@ static BOOL WINAPI ctrl_handler (DWORD type)
 
 
 #else
 #else
 
 
-static void unix_signal_handler (void *user, struct BUnixSignal_siginfo siginfo)
+static void unix_signal_handler (void *user, int signo)
 {
 {
-    ASSERT(siginfo.signo == SIGTERM || siginfo.signo == SIGINT)
+    ASSERT(signo == SIGTERM || signo == SIGINT)
     ASSERT(bsignal_global.initialized)
     ASSERT(bsignal_global.initialized)
     ASSERT(!bsignal_global.finished)
     ASSERT(!bsignal_global.finished)
     
     

+ 4 - 0
system/BSignal.h

@@ -36,6 +36,10 @@ typedef void (*BSignal_handler) (void *user);
  * Initializes signal handling.
  * Initializes signal handling.
  * The object is created in not capturing state.
  * The object is created in not capturing state.
  * {@link BLog_Init} must have been done.
  * {@link BLog_Init} must have been done.
+ * 
+ * WARNING: make sure this won't interfere with other components:
+ *   - on Linux, this uses {@link BUnixSignal} to catch SIGTERM and SIGINT,
+ *   - on Windows, this sets up a handler with SetConsoleCtrlHandler.
  *
  *
  * @param reactor {@link BReactor} from which the handler will be called
  * @param reactor {@link BReactor} from which the handler will be called
  * @param handler callback function invoked from the reactor
  * @param handler callback function invoked from the reactor

+ 1 - 2
system/BUnixSignal.c

@@ -64,8 +64,7 @@ static void signalfd_handler (BUnixSignal *o, int events)
     BLog(BLOG_DEBUG, "dispatching signal %d", signo);
     BLog(BLOG_DEBUG, "dispatching signal %d", signo);
     
     
     // call handler
     // call handler
-    struct BUnixSignal_siginfo dispatch_siginfo = { .signo = signo, .pid = siginfo.ssi_pid };
-    o->handler(o->user, dispatch_siginfo);
+    o->handler(o->user, signo);
     return;
     return;
 }
 }
 
 

+ 10 - 6
system/BUnixSignal.h

@@ -34,12 +34,13 @@
 #include <system/BReactor.h>
 #include <system/BReactor.h>
 #include <system/DebugObject.h>
 #include <system/DebugObject.h>
 
 
-struct BUnixSignal_siginfo {
-    int signo;
-    pid_t pid;
-};
-
-typedef void (*BUnixSignal_handler) (void *user, struct BUnixSignal_siginfo siginfo);
+/**
+ * Handler function called when a signal is received.
+ * 
+ * @param user as in {@link BUnixSignal_Init}
+ * @param signo signal number. Will be one of the signals provided to {@link signals}.
+ */
+typedef void (*BUnixSignal_handler) (void *user, int signo);
 
 
 /**
 /**
  * Object for catching unix signals.
  * Object for catching unix signals.
@@ -58,6 +59,9 @@ typedef struct {
  * Initializes the object.
  * Initializes the object.
  * {@link BLog_Init} must have been done.
  * {@link BLog_Init} must have been done.
  * 
  * 
+ * WARNING: for every signal number there should be at most one {@link BUnixSignal}
+ * object handling it (or anything else that could interfere).
+ * 
  * This blocks the signal using sigprocmask() and sets up signalfd() for receiving
  * This blocks the signal using sigprocmask() and sets up signalfd() for receiving
  * signals.
  * signals.
  *
  *