Project

General

Profile

Actions

Bug #117

closed

Broken sigwait on Mac OSX El Capitan

Added by François Félix Ingrand almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal

Description

Sigwait has a very weird behavior on OSX El Capitan.

First it sometimes return without setting the sig (you can set it before the call to -9999 and you get -9999 upon return) and this probably explained the 0 we were getting on SL (see old comment).

Second, I have to ignore a bunch of signals as I am getting them while running (for no apparent reasons).

Clearly, there is something I do not understand or which is acting funny.

Overall, I am not sure this "wait until somebody kill me" is a the good apparoach on OSX.


  /* we don't want to wait for codel-level signal */
  sigdelset(&sset, SIGUSR1);
  sigdelset(&sset, SIGUSR2);
  sigdelset(&sset, SIGCHLD);
  sigdelset(&sset, SIGINT);
  sigdelset(&sset, SIGQUIT);
  sigdelset(&sset, SIGPIPE);
  sigdelset(&sset, SIGTERM);

  /* wait for apocalypse */
  /* For some obscure reasons, Mac OSX SL sigwait can return with sig == 0 */
  sig = 0;
  do { sigwait(&sset, &sig); } while (sig == 0);

Actions #1

Updated by Anthony Mallet almost 7 years ago

Does this help?

diff --git server/main.c server/main.c
index a289751..6506618 100644
--- server/main.c
+++ server/main.c
@ -208,6 +208,7 @ genom_<"$comp">_run(void)
sigaddset(&sset, SIGUSR2);
sigaddset(&sset, SIGCHLD);

+ sigprocmask(SIG_BLOCK, &sset, NULL);
pthread_sigmask(SIG_BLOCK, &sset, NULL);

/* initialize comLib environnement */

Actions #2

Updated by François Félix Ingrand almost 7 years ago

Nope... still the same.

Actions #3

Updated by François Félix Ingrand almost 7 years ago

This solution is probably an unacceptable hack, as it completely avoid sigwait to handle termination, but at least for now, the Mac modules behave as expected, and properly quit when a kill request is sent. As a consequence, the drone experiment works "fine" on my MacBook Pro with Morse.

diff --git a/server/control_codels.c b/server/control_codels.c
index e8876a9..3a5f4b6 100644
--- a/server/control_codels.c
+++ b/server/control_codels.c
@@ -161,8 +161,13 @@ done:
 genom_event
 genom_kill_codel(genom_context self)
 {
+#ifdef __APPLE__
+  struct genom_component_data *gcd = self->data->self;
+  gcd->quit = TRUE;
+#else
   (void)self; /* fix -Wunused-parameter */
   kill(getpid(), SIGTERM);
+#endif
   return genom_ok;
 }

diff --git a/server/control_task.c b/server/control_task.c
index 7c3dfa1..fea2b25 100644
--- a/server/control_task.c
+++ b/server/control_task.c
@@ -73,7 +73,9 @@ genom_<"$comp">_init(void)
     genom_log_warn(1, "cannot create internal data structure");
     return NULL;
   }
-
+#ifdef __APPLE__
+  self->quit = FALSE;
+#endif
 <'if {![catch {$component ids} ids]} {'>
   genom_tinit_<"[$ids mangle]">(&self->ids);
 <'}'>
diff --git a/server/control_task.h b/server/control_task.h
index 8ee261f..6dc0a48 100644
--- a/server/control_task.h
+++ b/server/control_task.h
@@ -134,7 +177,10 @@ struct genom_context_data {
 };

 struct genom_component_data {
-<'if {![catch {$component ids} ids]} {'>
+#ifdef __APPLE__
+  int quit;
+#endif
+  <'if {![catch {$component ids} ids]} {'>
   <"[$ids declarator ids]">;
 <'}'>

diff --git a/server/main.c b/server/main.c
index a289751..2cb13dd 100644
--- a/server/main.c
+++ b/server/main.c
@@ -268,6 +269,12 @@ genom_<"$comp">_run(void)
     exit(2);
   }

+#ifdef __APPLE__
+  while (!(((struct genom_component_data *)<"$comp">_self)->quit)) {
+    sleep(1);
+  }
+  genom_log_info("terminating on quit");
+#else
   /* 
    * If SIGUSR1 is set to SIG_IGN, it can be two things:
    *   - the parent really ignores it, so it won't care about it
@@ -291,6 +298,7 @@ genom_<"$comp">_run(void)
   do { sigwait(&sset, &sig); } while (sig == 0);

   genom_log_info("terminating on %s signal request", strsignal(sig));
+#endif
   genom_<"$comp">_fini(<"$comp">_self);
   unlink(pid_file_path);
 }
Actions #4

Updated by François Félix Ingrand almost 7 years ago

Not to mention that it is not properly implemented for daemon mode...

Actions #5

Updated by Anthony Mallet almost 7 years ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF