Fix problem that syslog_facility don't change by reload
authorTakuma Hoshiai <hoshiai@sraoss.co.jp>
Tue, 8 Oct 2019 04:08:25 +0000 (13:08 +0900)
committerTakuma Hoshiai <hoshiai@sraoss.co.jp>
Tue, 8 Oct 2019 04:08:25 +0000 (13:08 +0900)
The cause is macro definition mistake. This fix unify macro definition, and delete old test code to use vsyslog().
Reported in bug 548.

configure.ac
src/include/utils/elog.h
src/utils/error/elog.c
src/watchdog/test/stab.c [deleted file]
src/watchdog/test/test.c [deleted file]
src/watchdog/test/wd_child_t.c [deleted file]
src/watchdog/test/wd_lifecheck_t.c [deleted file]
src/watchdog/test/wd_packet_t.c [deleted file]
src/watchdog/test/wd_ping_t.c [deleted file]

index c3116c3cf535ba92d189be6bd3aa9d8c332374f5..805fea0017d261cd458cbe7af2dd51485a71c240 100644 (file)
@@ -265,7 +265,7 @@ AC_TYPE_SIGNAL
 AC_FUNC_VPRINTF
 AC_FUNC_WAIT3
 AC_FUNC_ACCEPT_ARGTYPES
-AC_CHECK_FUNCS(setsid select socket sigprocmask strdup strerror strftime strtok asprintf vasprintf gai_strerror hstrerror pstat setproctitle vsyslog)
+AC_CHECK_FUNCS(setsid select socket sigprocmask strdup strerror strftime strtok asprintf vasprintf gai_strerror hstrerror pstat setproctitle syslog)
 
 dnl Checks for pg_config command.
 AC_CHECK_PROGS(PGCONFIG, pg_config)
index 49699ae33b97d9c61e930e1a94ac93791717198a..ecca20a93f149b8c69c1f5ee556edf50f06532f5 100644 (file)
@@ -499,7 +499,7 @@ typedef enum
 
 extern bool in_error_recursion_trouble(void);
 
-#ifdef HAVE_VSYSLOG
+#ifdef HAVE_SYSLOG
 extern void set_syslog_parameters(const char *ident, int facility);
 #endif
 
index 114083612560388e3c8fd65a0b43f768d404562e..3bcde5123e3ebd5ccace77367e27dfe2d1d2792d 100644 (file)
@@ -62,7 +62,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <ctype.h>
-#ifdef HAVE_VSYSLOG
+#ifdef HAVE_SYSLOG
 #include <syslog.h>
 #endif
 #include <string.h>
@@ -126,7 +126,7 @@ extern bool redirection_done;
  */
 emit_log_hook_type emit_log_hook = NULL;
 
-#ifdef HAVE_VSYSLOG
+#ifdef HAVE_SYSLOG
 
 /*
  * Max string length to send to syslog().  Note that this doesn't count the
@@ -1431,7 +1431,7 @@ GetErrorContextStack(void)
 }
 
 
-#ifdef HAVE_VSYSLOG
+#ifdef HAVE_SYSLOG
 
 /*
  * Set or update the parameters for syslog logging
@@ -1566,7 +1566,7 @@ write_syslog(int level, const char *line)
                syslog(level, "[%lu] %s", seq, line);
        }
 }
-#endif   /* HAVE_VSYSLOG */
+#endif   /* HAVE_SYSLOG */
 
 #ifdef WIN32
 /*
@@ -2161,7 +2161,7 @@ send_message_to_server_log(ErrorData *edata)
                }
        }
 
-#ifdef HAVE_VSYSLOG
+#ifdef HAVE_SYSLOG
        /* Write to syslog, if enabled */
        if (pool_config->log_destination & LOG_DESTINATION_SYSLOG)
     {
@@ -2199,7 +2199,7 @@ send_message_to_server_log(ErrorData *edata)
                }
                write_syslog(syslog_level, buf.data);
        }
-#endif   /* HAVE_VSYSLOG */
+#endif   /* HAVE_SYSLOG */
 
        if (pool_config->log_destination & LOG_DESTINATION_STDERR)
        {
diff --git a/src/watchdog/test/stab.c b/src/watchdog/test/stab.c
deleted file mode 100644 (file)
index ca017a1..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-#include <stdio.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <wait.h>
-
-#include "pool.h"
-#include "pool_config.h"
-
-#define MAXSTRFTIME 128
-
-int debug = 0;
-
-
-static char *nowsec(void);
-static void child_wait(int signo);
-
-void pool_error(const char *fmt,...)
-{
-       va_list         ap;
-       pool_sigset_t oldmask;
-#ifdef HAVE_ASPRINTF
-       char            *fmt2;
-    int         len;
-#endif
-       /* Write error message to syslog */
-       if (pool_config->logsyslog == 1) {
-          va_start(ap, fmt);
-          vsyslog(pool_config->syslog_facility | LOG_ERR, fmt, ap);
-          va_end(ap);
-          return;
-       }
-
-       POOL_SETMASK2(&BlockSig, &oldmask);
-       /*TODO
-       if (pool_config->print_timestamp)*/
-#ifdef HAVE_ASPRINTF
-         len = asprintf(&fmt2, "%s ERROR: pid %d: %s\n", nowsec(), (int)getpid(), fmt);
-
-   if (len >= 0 && fmt2)
-   {
-     va_start(ap, fmt);
-     vfprintf(stderr, fmt2, ap);
-     va_end(ap);
-     fflush(stderr);
-        free(fmt2);
-   }
-#else
-         fprintf(stderr, "%s ERROR: pid %d: ", nowsec(), (int)getpid());
-       else
-         fprintf(stderr, "ERROR: pid %d: ", (int)getpid());
-
-       va_start(ap, fmt);
-       vfprintf(stderr, fmt, ap);
-       va_end(ap);
-       fprintf(stderr, "\n");
-#endif
-
-       POOL_SETMASK(&oldmask);
-}
-
-static char *nowsec(void)
-{
-       static char strbuf[MAXSTRFTIME];
-       time_t now = time(NULL);
-
-       strftime(strbuf, MAXSTRFTIME, "%Y-%m-%d %H:%M:%S", localtime(&now));
-       return strbuf;
-}
-
-size_t
-strlcpy(char *dst, const char *src, size_t siz)
-{
-       char       *d = dst;
-       const char *s = src;
-       size_t          n = siz;
-
-       /* Copy as many bytes as will fit */
-       if (n != 0)
-       {
-               while (--n != 0)
-               {
-                       if ((*d++ = *s++) == '\0')
-                               break;
-               }
-       }
-
-       /* Not enough room in dst, add NUL and traverse rest of src */
-       if (n == 0)
-       {
-               if (siz != 0)
-                       *d = '\0';                      /* NUL-terminate dst */
-               while (*s++)
-                       ;
-       }
-
-       return (s - src - 1);           /* count does not include NUL */
-}
-
-static void
-child_wait(int signo)
-{
-       pid_t pid = 0;
-
-       do {
-               int ret;
-               pid = waitpid(-1,&ret,WNOHANG);
-       } while(pid > 0);
-}
-
-void
-wd_exit(int exit_signo)
-{
-       sigset_t mask;
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGTERM);
-       sigaddset(&mask, SIGINT);
-       sigaddset(&mask, SIGQUIT);
-       sigaddset(&mask, SIGCHLD);
-       sigprocmask(SIG_BLOCK, &mask, NULL);
-
-       wd_notice_server_down();
-
-       pool_shmem_exit(1);
-
-       kill (0, exit_signo);
-
-       child_wait(0);
-
-       exit(0);
-}
-
-int pool_memset_system_db_info (SystemDBInfo *info)
-{
-       return 0;
-}
-
-int
-pool_query_cache_table_exists(void)
-{
-       return 0;
-}
-
diff --git a/src/watchdog/test/test.c b/src/watchdog/test/test.c
deleted file mode 100644 (file)
index 56440be..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "pool.h"
-#include "pool_config.h"
-#include "watchdog.h"
-#include "wd_ext.h"
-
-pid_t mypid;
-
-static void wdlist_dump(void);
-extern void wd_exit(int exit_signo);
-
-int
-main(int argc, char * argv[])
-{
-       int rtn;
-
-       signal(SIGCHLD, SIG_DFL);
-       signal(SIGHUP, SIG_IGN);        
-       signal(SIGINT, wd_exit);        
-       signal(SIGQUIT, wd_exit);       
-       signal(SIGTERM, wd_exit);       
-       signal(SIGPIPE, SIG_IGN);       
-
-       mypid = getpid();
-       rtn = pool_init_config();
-
-       pool_config->recovery_user = "mitani";
-       pool_config->trusted_servers = "paris";
-       pool_config->delegate_IP = "192.168.100.99";
-       pool_config->pgpool2_hostname = "vm1";
-       pool_config->port = 5432;
-       pool_config->wd_port = 9999;
-       pool_config->other_wd->num_wd = 2;
-       strcpy(pool_config->other_wd->wd_info[0].hostname ,"vm2");
-       pool_config->other_wd->wd_info[0].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[0].wd_port = 9999;
-       pool_config->other_wd->wd_info[0].status = WD_INIT;
-       strcpy(pool_config->other_wd->wd_info[1].hostname ,"paris");
-       pool_config->other_wd->wd_info[1].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[1].wd_port = 9999;
-       pool_config->other_wd->wd_info[1].status = WD_INIT;
-       pool_config->ping_path = "/bin";
-       pool_config->ifconfig_path = "/sbin";
-       pool_config->if_up_cmd = "ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0";
-       pool_config->if_down_cmd = "ifconfig eth0:0 down";
-       pool_config->wd_interval = 3;
-       pool_config->wd_life_point = 1;
-       
-       wd_main(3);
-
-       for (;;)
-       {
-               wdlist_dump();
-               sleep(5);
-       }
-       wd_exit(15);
-
-}
-
-
-static void
-wdlist_dump(void)
-{
-       int i;
-       WdInfo * p = WD_List;
-
-       i = 0;
-       while (p->status != WD_END)
-       {
-               printf("%d:s[%d] ts[%d] tu[%d] h[%s] pp[%d] wp[%d]\n",
-                       i,p->status,
-                       p->tv.tv_sec, p->tv.tv_usec,
-                       p->hostname,
-                       p->pgpool_port,
-                       p->wd_port);
-               p++;
-               i++;
-       }
-}
diff --git a/src/watchdog/test/wd_child_t.c b/src/watchdog/test/wd_child_t.c
deleted file mode 100644 (file)
index b9e69e8..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "pool.h"
-#include "pool_config.h"
-#include "watchdog.h"
-#include "wd_ext.h"
-
-pid_t mypid;
-WdInfo * WD_List = NULL;               /* watchdog server list */
-
-static void wdlist_dump(void);
-extern void wd_exit(int exit_signo);
-
-int
-main(int argc, char * argv[])
-{
-       int rtn;
-
-       signal(SIGCHLD, SIG_DFL);
-       signal(SIGHUP, SIG_IGN);        
-       signal(SIGINT, wd_exit);        
-       signal(SIGQUIT, wd_exit);       
-       signal(SIGTERM, wd_exit);       
-       signal(SIGPIPE, SIG_IGN);       
-
-       mypid = getpid();
-       rtn = pool_init_config();
-
-       pool_config->recovery_user = "mitani";
-       pool_config->trusted_servers = "paris";
-       pool_config->delegate_IP = "192.168.100.99";
-       pool_config->pgpool2_hostname = "vm1";
-       pool_config->port = 5432;
-       pool_config->wd_port = 9999;
-       pool_config->other_wd->num_wd = 2;
-       strcpy(pool_config->other_wd->wd_info[0].hostname ,"vm2");
-       pool_config->other_wd->wd_info[0].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[0].wd_port = 9999;
-       pool_config->other_wd->wd_info[0].status = WD_INIT;
-       strcpy(pool_config->other_wd->wd_info[1].hostname ,"paris");
-       pool_config->other_wd->wd_info[1].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[1].wd_port = 9999;
-       pool_config->other_wd->wd_info[1].status = WD_INIT;
-       pool_config->ping_path = "/bin";
-       pool_config->ifconfig_path = "/sbin";
-       pool_config->if_up_cmd = "ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0";
-       pool_config->if_down_cmd = "ifconfig eth0:0 down";
-       pool_config->wd_interval = 3;
-       pool_config->wd_life_point = 1;
-       
-       wd_init();
-       
-       wd_child(1);
-
-       for (;;)
-       {
-               wdlist_dump();
-               sleep(5);
-       } 
-
-}
-
-
-static void
-wdlist_dump(void)
-{
-       int i;
-       WdInfo * p = WD_List;
-
-       i = 0;
-       while (p->status != WD_END)
-       {
-               printf("%d:s[%d] ts[%d] tu[%d] h[%s] pp[%d] wp[%d]\n",
-                       i,p->status,
-                       p->tv.tv_sec, p->tv.tv_usec,
-                       p->hostname,
-                       p->pgpool_port,
-                       p->wd_port);
-               p++;
-               i++;
-       }
-}
diff --git a/src/watchdog/test/wd_lifecheck_t.c b/src/watchdog/test/wd_lifecheck_t.c
deleted file mode 100644 (file)
index e162828..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "pool.h"
-#include "pool_config.h"
-#include "watchdog.h"
-#include "wd_ext.h"
-
-pid_t mypid;
-WdInfo * WD_List = NULL;               /* watchdog server list */
-
-static void wdlist_dump(void);
-extern void wd_exit(int exit_signo);
-
-int
-main(int argc, char * argv[])
-{
-       int rtn;
-
-       signal(SIGCHLD, SIG_DFL);
-       signal(SIGHUP, SIG_IGN);        
-       signal(SIGINT, wd_exit);        
-       signal(SIGQUIT, wd_exit);       
-       signal(SIGTERM, wd_exit);       
-       signal(SIGPIPE, SIG_IGN);       
-
-       mypid = getpid();
-       rtn = pool_init_config();
-
-       pool_config->recovery_user = "mitani";
-       pool_config->trusted_servers = "paris";
-       pool_config->delegate_IP = "192.168.100.99";
-       pool_config->pgpool2_hostname = "vm1";
-       pool_config->port = 5432;
-       pool_config->wd_port = 9999;
-       pool_config->other_wd->num_wd = 2;
-       strcpy(pool_config->other_wd->wd_info[0].hostname ,"vm2");
-       pool_config->other_wd->wd_info[0].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[0].wd_port = 9999;
-       pool_config->other_wd->wd_info[0].status = WD_INIT;
-       strcpy(pool_config->other_wd->wd_info[1].hostname ,"paris");
-       pool_config->other_wd->wd_info[1].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[1].wd_port = 9999;
-       pool_config->other_wd->wd_info[1].status = WD_INIT;
-       pool_config->ping_path = "/bin";
-       pool_config->ifconfig_path = "/sbin";
-       pool_config->if_up_cmd = "ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0";
-       pool_config->if_down_cmd = "ifconfig eth0:0 down";
-       pool_config->wd_interval = 3;
-       pool_config->wd_life_point = 1;
-       
-       wd_init();
-
-       for (;;)
-       {
-               wdlist_dump();
-               wd_lifecheck();
-               sleep(pool_config->wd_interval);
-       }
-       wd_exit(15);
-
-}
-
-
-static void
-wdlist_dump(void)
-{
-       int i;
-       WdInfo * p = WD_List;
-
-       i = 0;
-       while (p->status != WD_END)
-       {
-               printf("%d:s[%d] ts[%d] tu[%d] h[%s] pp[%d] wp[%d]\n",
-                       i,p->status,
-                       p->tv.tv_sec, p->tv.tv_usec,
-                       p->hostname,
-                       p->pgpool_port,
-                       p->wd_port);
-               p++;
-               i++;
-       }
-}
diff --git a/src/watchdog/test/wd_packet_t.c b/src/watchdog/test/wd_packet_t.c
deleted file mode 100644 (file)
index 0740a11..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include "pool.h"
-#include "pool_config.h"
-#include "watchdog.h"
-#include "wd_ext.h"
-
-pid_t mypid;
-WdInfo * WD_List = NULL;               /* watchdog server list */
-
-static void wdlist_dump(void);
-extern void wd_exit(int exit_signo);
-
-int
-main(int argc, char * argv[])
-{
-       int rtn;
-
-       signal(SIGCHLD, SIG_DFL);
-       signal(SIGHUP, SIG_IGN);        
-       signal(SIGINT, wd_exit);        
-       signal(SIGQUIT, wd_exit);       
-       signal(SIGTERM, wd_exit);       
-       signal(SIGPIPE, SIG_IGN);       
-
-       mypid = getpid();
-       rtn = pool_init_config();
-
-       pool_config->recovery_user = "mitani";
-       pool_config->trusted_servers = "paris";
-       pool_config->delegate_IP = "192.168.100.99";
-       pool_config->pgpool2_hostname = "vm1";
-       pool_config->port = 5432;
-       pool_config->wd_port = 9999;
-       pool_config->other_wd->num_wd = 2;
-       strcpy(pool_config->other_wd->wd_info[0].hostname ,"vm2");
-       pool_config->other_wd->wd_info[0].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[0].wd_port = 9999;
-       pool_config->other_wd->wd_info[0].status = WD_INIT;
-       strcpy(pool_config->other_wd->wd_info[1].hostname ,"paris");
-       pool_config->other_wd->wd_info[1].pgpool_port = 5432;
-       pool_config->other_wd->wd_info[1].wd_port = 9999;
-       pool_config->other_wd->wd_info[1].status = WD_INIT;
-       pool_config->ping_path = "/bin";
-       pool_config->ifconfig_path = "/sbin";
-       pool_config->if_up_cmd = "ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0";
-       pool_config->if_down_cmd = "ifconfig eth0:0 down";
-       pool_config->wd_interval = 3;
-       pool_config->wd_life_point = 1;
-       
-       wd_init();
-
-       for (;;)
-       {
-               wdlist_dump();
-               sleep(5);
-               wd_lifecheck();
-       }
-       wd_exit(15);
-
-}
-
-
-static void
-wdlist_dump(void)
-{
-       int i;
-       WdInfo * p = WD_List;
-
-       i = 0;
-       while (p->status != WD_END)
-       {
-               printf("%d:s[%d] ts[%d] tu[%d] h[%s] pp[%d] wp[%d]\n",
-                       i,p->status,
-                       p->tv.tv_sec, p->tv.tv_usec,
-                       p->hostname,
-                       p->pgpool_port,
-                       p->wd_port);
-               p++;
-               i++;
-       }
-}
diff --git a/src/watchdog/test/wd_ping_t.c b/src/watchdog/test/wd_ping_t.c
deleted file mode 100644 (file)
index 0b90178..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <stdio.h>
-#include "watchdog.h"
-
-extern int wd_is_upper_ok(char * server_list);
-
-int
-main(int argc,char * argv[])
-{
-       int rtn;
-       rtn = wd_is_upper_ok(argv[1]);
-       if (rtn == WD_OK)
-       {
-               printf("%s is ok",argv[1]);
-       }
-       else
-       {
-               printf("%s is ng",argv[1]);
-       }
-       return 0;
-}