make yaz daemon facility to re-open log file YAZ-818
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 28 Jan 2015 15:46:56 +0000 (16:46 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 28 Jan 2015 15:46:56 +0000 (16:46 +0100)
include/yaz/daemon.h
src/daemon.c

index 5ec2d88..371a21c 100644 (file)
@@ -41,6 +41,7 @@ YAZ_BEGIN_CDECL
 #define YAZ_DAEMON_FORK 1
 #define YAZ_DAEMON_DEBUG 2
 #define YAZ_DAEMON_KEEPALIVE 4
 #define YAZ_DAEMON_FORK 1
 #define YAZ_DAEMON_DEBUG 2
 #define YAZ_DAEMON_KEEPALIVE 4
+#define YAZ_DAEMON_LOG_REOPEN 8
 
 /** \brief daemon utility.
     \param progname program name for logging purposes.
 
 /** \brief daemon utility.
     \param progname program name for logging purposes.
@@ -61,6 +62,8 @@ YAZ_BEGIN_CDECL
 
     Flag YAZ_DAEMON_KEEPALIVE: Repeatedly calls work handler if it makes a
     "fatal" error.
 
     Flag YAZ_DAEMON_KEEPALIVE: Repeatedly calls work handler if it makes a
     "fatal" error.
+
+    Flag YAZ_DAEMON_KEEPALIVE: Re-opens yaz log if SIGHUP is received
 */
 YAZ_EXPORT
 int yaz_daemon(const char *progname,
 */
 YAZ_EXPORT
 int yaz_daemon(const char *progname,
index 3ece89c..4448e1d 100644 (file)
@@ -73,6 +73,13 @@ static void normal_stop_handler(int num)
     }
 }
 
     }
 }
 
+static void log_reopen_handler(int num)
+{
+    yaz_log_reopen();
+    if (child_pid)
+        kill(child_pid, num);
+}
+
 static void sigusr2_handler(int num)
 {
     child_got_signal_from_us = 1;
 static void sigusr2_handler(int num)
 {
     child_got_signal_from_us = 1;
@@ -88,7 +95,6 @@ static void keepalive(void (*work)(void *data), void *data)
     int no_sigbus = 0;
     int run = 1;
     int cont = 1;
     int no_sigbus = 0;
     int run = 1;
     int cont = 1;
-    void (*old_sighup)(int);
     void (*old_sigterm)(int);
     void (*old_sigusr1)(int);
     struct sigaction sa2, sa1;
     void (*old_sigterm)(int);
     void (*old_sigusr1)(int);
     struct sigaction sa2, sa1;
@@ -97,7 +103,6 @@ static void keepalive(void (*work)(void *data), void *data)
 
     /* keep signals in their original state and make sure that some signals
        to parent process also gets sent to the child..  */
 
     /* keep signals in their original state and make sure that some signals
        to parent process also gets sent to the child..  */
-    old_sighup = signal(SIGHUP, normal_stop_handler);
     old_sigterm = signal(SIGTERM, normal_stop_handler);
     old_sigusr1 = signal(SIGUSR1, normal_stop_handler);
 
     old_sigterm = signal(SIGTERM, normal_stop_handler);
     old_sigusr1 = signal(SIGUSR1, normal_stop_handler);
 
@@ -119,7 +124,6 @@ static void keepalive(void (*work)(void *data), void *data)
         else if (p == 0)
         {
             /* child */
         else if (p == 0)
         {
             /* child */
-            signal(SIGHUP, old_sighup);  /* restore */
             signal(SIGTERM, old_sigterm);/* restore */
             signal(SIGUSR1, old_sigusr1);/* restore */
             sigaction(SIGUSR2, &sa1, NULL);
             signal(SIGTERM, old_sigterm);/* restore */
             signal(SIGUSR1, old_sigusr1);/* restore */
             sigaction(SIGUSR2, &sa1, NULL);
@@ -322,6 +326,10 @@ int yaz_daemon(const char *progname,
 
     write_pidfile(pid_fd);
 
 
     write_pidfile(pid_fd);
 
+    if (flags & YAZ_DAEMON_LOG_REOPEN)
+    {
+        signal(SIGHUP, log_reopen_handler);
+    }
     if (flags & YAZ_DAEMON_KEEPALIVE)
     {
         keepalive(work, data);
     if (flags & YAZ_DAEMON_KEEPALIVE)
     {
         keepalive(work, data);