aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2012-07-13 18:52:06 +0200
committerThomas White <taw@physics.org>2012-07-13 18:52:06 +0200
commitcc22322a0365213994647b9ba0bc04d0eec04217 (patch)
tree42d3da7a1db8eff7e1eb657c956446088e5f660f
parentcb2623e64fed28efdc0d3b3de2338ab57684985b (diff)
Skeleton signal handler
-rw-r--r--src/indexamajig.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/indexamajig.c b/src/indexamajig.c
index 5a8bd816..f560b7b8 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -47,6 +47,7 @@
#include <pthread.h>
#include <sys/wait.h>
#include <fcntl.h>
+#include <signal.h>
#ifdef HAVE_CLOCK_GETTIME
#include <time.h>
@@ -671,6 +672,14 @@ static void run_reader(int *stream_pipe_read, int n_proc, FILE *ofh)
}
+static void signal_handler(int sig, siginfo_t *si, void *uc_v)
+{
+ struct ucontext_t *uc = uc_v;
+
+ STATUS("Signal!\n");
+}
+
+
int main(int argc, char *argv[])
{
int c;
@@ -736,6 +745,8 @@ int main(int argc, char *argv[])
int allDone;
int *finished;
pid_t pr;
+ struct sigaction sa;
+ int r;
copyme = new_copy_hdf5_field_list();
if ( copyme == NULL ) {
@@ -1196,6 +1207,16 @@ int main(int argc, char *argv[])
}
+ /* Set up signal handler to take action if any children die */
+ sa.sa_flags = SA_SIGINFO | SA_NOCLDSTOP;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_sigaction = signal_handler;
+ r = sigaction(SIGCHLD, &sa, NULL);
+ if ( r == -1 ) {
+ ERROR("Failed to set signal handler!\n");
+ return 1;
+ }
+
/* Free resources needed by reader only */
if ( ofh != stdout ) fclose(ofh);
for ( i=0; i<n_proc; i++ ) {