Commit 3d978858 authored by Mike Hibler's avatar Mike Hibler

Try harder to make sure signals are handled in the main thread only.

Looks like they were mostly being caught in the event system dispatcher
thread before. Let's see if that was causing problems...
parent 26f303de
......@@ -121,7 +121,7 @@ static void sigpass(int sig)
time_t ts = time(NULL);
info("event-sched[%d]: received signal %d at %s",
getpid(), sig, ctime(&ts));
if (emcd_pid != -1)
kill(emcd_pid, sig);
if (vmcd_pid != -1)
......@@ -252,6 +252,7 @@ main(int argc, char *argv[])
char *keyfile = NULL;
char buf[BUFSIZ];
int c;
sigset_t mask;
// sleep(600);
......@@ -360,6 +361,12 @@ main(int argc, char *argv[])
if (log)
loginit(0, log);
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGQUIT);
sigaddset(&mask, SIGHUP);
signal(SIGTERM, sigpass);
signal(SIGINT, sigpass);
signal(SIGQUIT, sigpass);
......@@ -384,12 +391,17 @@ main(int argc, char *argv[])
(port ? port : ""));
server = buf;
/* XXX make sure we don't catch signals in event (pubsub) dispatcher */
pthread_sigmask(SIG_BLOCK, &mask, NULL);
/* Register with the event system: */
handle = event_register_withkeyfile(server, 1, keyfile);
if (handle == NULL) {
fatal("could not register with event system");
}
pthread_sigmask(SIG_UNBLOCK, &mask, NULL);
/* Make a (not yet populated) list of things to do after initial swapin */
ns_sequence = create_timeline_agent(TA_SEQUENCE);
ns_sequence->ta_local_agent.la_link.ln_Name = ns_sequence_agent.name;
......
......@@ -34,6 +34,7 @@
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include "local-agent.h"
......@@ -121,13 +122,29 @@ int local_agent_queue(local_agent_t la, sched_event_t *se)
lnAddTail(&la->la_queue, &lae->lae_link);
if (la->la_flags & LAF_LOOPING) {
// thread is already running, nothing to do...
}
else if ((retval = pthread_create(&pt,
} else {
sigset_t mask, omask;
/*
* XXX we don't want any of these threads to
* handle our termination signals, so block
* them temporarily so that new thread will
* have them blocked.
*/
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGQUIT);
sigaddset(&mask, SIGHUP);
pthread_sigmask(SIG_BLOCK, &mask, &omask);
if ((retval = pthread_create(&pt,
NULL,
la->la_looper,
la)) == 0) {
la->la_flags |= LAF_LOOPING;
pthread_detach(pt);
la->la_flags |= LAF_LOOPING;
pthread_detach(pt);
}
pthread_sigmask(SIG_SETMASK, &omask, NULL);
}
if (pthread_mutex_unlock(&la->la_mutex) != 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment