From 59345feeb2f25c4fdedc39a6d3a47beae2ba2a54 Mon Sep 17 00:00:00 2001 From: hadaq Date: Wed, 14 Nov 2001 17:18:52 +0000 Subject: [PATCH] The protocol for stopping workers has changed. It is now also a two step procedure, Worker_halt signals the worker to stop processing but keep the status segment alive. Worker stop afterwards really kills the worker. --- hadaq/Makefile | 2 +- hadaq/agent.c | 3 ++- hadaq/daq_lib.c | 4 +++- hadaq/param.tcl | 2 +- hadaq/worker.c | 60 +++++++++++++++++++++++++++++++++++++++++-------- hadaq/worker.h | 1 + 6 files changed, 59 insertions(+), 13 deletions(-) diff --git a/hadaq/Makefile b/hadaq/Makefile index b35f899..8a1c05f 100644 --- a/hadaq/Makefile +++ b/hadaq/Makefile @@ -11,7 +11,7 @@ # $ . makeenv LYNXOS TOF # $ . makeenv UNIX SOFT -COPTS = -O3 -finline-functions -DNDEBUG +COPTS = -g -UNDEBUG CFLAGS = $(COPTS) $(INCLUDES) $(DEFINES) DAQCTRL_OBJS = daqctrl.o daq_lib.o \ diff --git a/hadaq/agent.c b/hadaq/agent.c index 71c3e68..c0d315b 100644 --- a/hadaq/agent.c +++ b/hadaq/agent.c @@ -1,4 +1,4 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/agent.c,v 6.5 2001-03-07 16:02:43 hades Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/agent.c,v 6.6 2001-11-14 17:18:52 hadaq Exp $"; #include #include "agent.h" @@ -76,6 +76,7 @@ int *rpcworker_stop_1(int *id, CLIENT * cl) { static int retVal; + Worker_halt(getWorker(*id), 15); Worker_stop(getWorker(*id), 15); removeWorker(*id); diff --git a/hadaq/daq_lib.c b/hadaq/daq_lib.c index de80ec0..bb8fe67 100644 --- a/hadaq/daq_lib.c +++ b/hadaq/daq_lib.c @@ -1,4 +1,4 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/Attic/daq_lib.c,v 6.6 2001-03-07 16:02:43 hades Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/Attic/daq_lib.c,v 6.7 2001-11-14 17:18:52 hadaq Exp $"; #include @@ -38,6 +38,8 @@ int Daq_start(const char *n, const Param *p) int Daq_stop(const char *n, const Param *p) { + Worker_halt(n, 15); + puts(Worker_status(n)); Worker_stop(n, 15); return 0; } diff --git a/hadaq/param.tcl b/hadaq/param.tcl index 8e5e898..ccd6049 100644 --- a/hadaq/param.tcl +++ b/hadaq/param.tcl @@ -1,7 +1,7 @@ set evtbuild(file) ./daq_evtbuild set evtbuild(stndln) 0 set evtbuild(priority) -2 -set evtbuild(outdev) file +set evtbuild(outdev) null set evtbuild(outpath) /tmp set evtbuild(expid) ha set netmem(file) ./daq_netmem diff --git a/hadaq/worker.c b/hadaq/worker.c index 94e2bc7..85ee33f 100644 --- a/hadaq/worker.c +++ b/hadaq/worker.c @@ -1,4 +1,4 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.9 2001-11-14 09:29:27 hadaq Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/worker.c,v 6.10 2001-11-14 17:18:52 hadaq Exp $"; #define _POSIX_C_SOURCE 199309L @@ -162,6 +162,8 @@ Worker *Worker_initBegin(const char *name, void (*sigHandler) (int), int priorit { Worker *retVal; Worker *my; + int s0; + int s1; if (NULL == (my = malloc(sizeof(Worker)))) { syslog(LOG_ERR, "%s:%d: %s", __FILE__, __LINE__, strerror(errno)); @@ -172,19 +174,24 @@ Worker *Worker_initBegin(const char *name, void (*sigHandler) (int), int priorit my->pid = getpid(); my->isStandalone = isStandalone; - if (-1 == installSigHandlers(my, SIGINT, SIGTERM, sigHandler)) { + if (!my->isStandalone) { + s0 = SIGUSR1; + s1 = SIGUSR2; + } else { + s0 = SIGINT; + s1 = SIGTERM; + } + + if (-1 == installSigHandlers(my, s0, s1, sigHandler)) { syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno)); - Worker_fini(my); retVal = NULL; } else if (-1 == createStatShm(my)) { syslog(LOG_DEBUG, "%s:%d: %s", __FILE__, __LINE__, strerror(errno)); - Worker_fini(my); + removeSigHandlers(my); retVal = NULL; } else { - unsigned long *pidP; - - pidP = Worker_addStatistic(my, "pid"); - *pidP = my->pid; + my->pidP = Worker_addStatistic(my, "pid"); + *my->pidP = my->pid; if (0 > changePriority(priority)) { syslog(LOG_WARNING, "changeing priority: %s", strerror(errno)); @@ -208,6 +215,21 @@ void Worker_initEnd(Worker *my) void Worker_fini(Worker *my) { + + if (!my->isStandalone) { + sigset_t sigMaskS, *sigMask = &sigMaskS; + + removeSigHandlers(my); + installSigHandlers(my, SIGINT, SIGTERM, noopHandler); + + *my->pidP |= (1 << 31); + + /* BUGBUG there should be a timeout here */ + sigemptyset(sigMask); + sigsuspend(sigMask); + } + + removeStatShm(my); removeSigHandlers(my); @@ -289,7 +311,7 @@ char *Worker_status(const char *name) return retVal; } -void Worker_stop(const char *name, int timeout) +void Worker_halt(const char *name, int timeout) { Worker myS, *my = &myS; @@ -297,12 +319,32 @@ void Worker_stop(const char *name, int timeout) if (0 == openStatShm(my)) { my->pid = my->statistics[0].value; + if (my->pid > 0) { + if (0 == kill(my->pid, SIGUSR1)) { + while (((my->pid = my->statistics[0].value) & (1 << 31)) == 0) { + sleep(1); + } + } + } + closeStatShm(my); + } +} + +void Worker_stop(const char *name, int timeout) +{ + Worker myS, *my = &myS; + + strcpy(my->name, name); + + if (0 == openStatShm(my)) { + my->pid = my->statistics[0].value & ~(1 << 31); if (my->pid > 0) { if (0 == kill(my->pid, SIGTERM)) { sleep(1); wait(NULL); } } + closeStatShm(my); } } diff --git a/hadaq/worker.h b/hadaq/worker.h index 6df8835..a7e4f4f 100644 --- a/hadaq/worker.h +++ b/hadaq/worker.h @@ -24,6 +24,7 @@ typedef struct WorkerS { PsxShm *shm; Statistic *statistics; pid_t pid; + unsigned long *pidP; int isStandalone; } Worker; -- 2.43.0