From: Takuma Hoshiai Date: Tue, 8 Oct 2019 04:10:32 +0000 (+0900) Subject: Fix problem that syslog_facility don't change by reload X-Git-Tag: V3_4_26~7 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=ee46069b7d2c4e4b804b7d1df2ee5a33668ac8b2;p=pgpool2.git Fix problem that syslog_facility don't change by reload The cause is macro definition mistake. This fix unify macro definition, and delete old test code to use vsyslog(). Reported in bug 548. --- diff --git a/configure.ac b/configure.ac index fbcacb2b2..72bcf7762 100644 --- a/configure.ac +++ b/configure.ac @@ -248,7 +248,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) diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index 065c7e567..0057d8562 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -491,7 +491,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 diff --git a/src/main/main.c b/src/main/main.c index 5a022b977..0dd6c1c2b 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -299,7 +299,7 @@ int main(int argc, char **argv) else daemonize(); -#ifdef HAVE_VSYSLOG +#ifdef HAVE_SYSLOG set_syslog_parameters(pool_config->syslog_ident ? pool_config->syslog_ident : "pgpool", pool_config->syslog_facility); #endif diff --git a/src/utils/error/elog.c b/src/utils/error/elog.c index 36d29d5da..332e60fc1 100644 --- a/src/utils/error/elog.c +++ b/src/utils/error/elog.c @@ -62,7 +62,7 @@ #include #include #include -#ifdef HAVE_VSYSLOG +#ifdef HAVE_SYSLOG #include #endif #include @@ -123,7 +123,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 @@ -1427,7 +1427,7 @@ GetErrorContextStack(void) } -#ifdef HAVE_VSYSLOG +#ifdef HAVE_SYSLOG /* * Set or update the parameters for syslog logging @@ -1562,7 +1562,7 @@ write_syslog(int level, const char *line) syslog(level, "[%lu] %s", seq, line); } } -#endif /* HAVE_VSYSLOG */ +#endif /* HAVE_SYSLOG */ #ifdef WIN32 /* @@ -2133,7 +2133,7 @@ send_message_to_server_log(ErrorData *edata) } } -#ifdef HAVE_VSYSLOG +#ifdef HAVE_SYSLOG /* Write to syslog, if enabled */ if (pool_config->logsyslog == 1) { @@ -2171,7 +2171,7 @@ send_message_to_server_log(ErrorData *edata) if (pool_config->logsyslog == 1) write_syslog(syslog_level, buf.data); } -#endif /* HAVE_VSYSLOG */ +#endif /* HAVE_SYSLOG */ write_console(buf.data, buf.len); pfree(buf.data); diff --git a/src/watchdog/test/stab.c b/src/watchdog/test/stab.c deleted file mode 100644 index 1fd7241c8..000000000 --- a/src/watchdog/test/stab.c +++ /dev/null @@ -1,151 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#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; -#ifdef HAVE_ASPRINTF - char *fmt2; - int len; -#endif - -#ifdef HAVE_SIGPROCMASK - sigset_t oldmask; -#else - int oldmask; -#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 index 56440be43..000000000 --- a/src/watchdog/test/test.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#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 index b9e69e847..000000000 --- a/src/watchdog/test/wd_child_t.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#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 index e1628287d..000000000 --- a/src/watchdog/test/wd_lifecheck_t.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#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 index 0740a117e..000000000 --- a/src/watchdog/test/wd_packet_t.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#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 index 0b90178f9..000000000 --- a/src/watchdog/test/wd_ping_t.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#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; -}