From 44d8c419373fafe932570d06576bc7778ddc746e Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 9 Nov 2010 05:37:20 +0000 Subject: [PATCH] pass sighup into child --- direct/src/autorestart/autorestart.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/direct/src/autorestart/autorestart.c b/direct/src/autorestart/autorestart.c index d5f8c91c16..c8bce825a2 100644 --- a/direct/src/autorestart/autorestart.c +++ b/direct/src/autorestart/autorestart.c @@ -232,6 +232,7 @@ do_watchdog(int *status_ptr) { curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, watchdog_bitbucket); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer); curl_easy_setopt(curl, CURLOPT_USERAGENT, "autorestart"); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); res = curl_easy_perform(curl); while (res == 0) { @@ -395,6 +396,23 @@ sigterm_handler() { exit(1); } +void +sighup_handler() { + time_t now; + char time_buffer[TIME_BUFFER_SIZE]; + + now = time(NULL); + strftime(time_buffer, TIME_BUFFER_SIZE, "%T on %A, %d %b %Y", localtime(&now)); + + fprintf(stderr, "\nsighup caught at %s.\n", time_buffer); + if (child_pid == 0) { + fprintf(stderr, "no child process.\n\n"); + + } else { + kill(child_pid, SIGHUP); + } +} + void sigalarm_handler() { fprintf(stderr, "sleep epoch was complete.\n"); @@ -423,6 +441,15 @@ do_autorestart() { perror("sigaction"); } + /* Set up a signal handler to trap SIGHUP. We pass this into the + child. */ + sa.sa_handler = sighup_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGHUP, &sa, NULL) < 0) { + perror("sigaction"); + } + if (logfile_fd >= 0) { /* If we have a logfile, dup it onto stdout and stderr. */ dup2(logfile_fd, STDOUT_FILENO);