extern pid_t myProcPid; /* process pid */
extern ProcessType processType;
extern ProcessState processState;
+extern void set_application_name(ProcessType ptype);
+extern void set_application_name_with_string(char *string);
+extern void set_application_name_with_suffix(ProcessType ptype, int suffix);
+extern char *get_application_name(void);
+extern char *get_application_name_for_procees(ProcessType ptype);
+
+void SetProcessGlobalVaraibles(ProcessType pType);
+
extern volatile SI_ManageInfo *si_manage_info;
extern volatile sig_atomic_t sigusr2_received;
extern POOL_NODE_STATUS * pool_get_node_status(void);
extern void pool_set_backend_status_changed_time(int backend_id);
extern int get_next_master_node(void);
-extern void set_application_name(ProcessType ptype);
-extern void set_application_name_with_string(char *string);
-extern void set_application_name_with_suffix(ProcessType ptype, int suffix);
-extern char *get_application_name(void);
hba_file = make_absolute_path(hba_file_path, base_dir);
mypid = getpid();
- myProcPid = mypid;
+ SetProcessGlobalVaraibles(PT_MAIN);
+
pool_init_config();
#endif
mypid = getpid();
- myProcPid = mypid;
+ SetProcessGlobalVaraibles(PT_MAIN);
write_pid_file();
if (chdir("/"))
ereport(WARNING,
case 0:
on_exit_reset();
- myProcPid = getpid();
- processType = PT_LOGGER;
+ SetProcessGlobalVaraibles(PT_LOGGER);
/* do the work */
SysLoggerMain(0, NULL);
break;
/* For PostmasterRandom */
gettimeofday(&random_start_time, NULL);
- /* Set the process type variable */
- processType = PT_MAIN;
- set_application_name(processType);
processState = INITIALIZING;
/*
if (pid == 0)
{
on_exit_reset();
+ SetProcessGlobalVaraibles(PT_PCP);
close(pipe_fds[0]);
close(pipe_fds[1]);
- /* Set the process type variable */
- processType = PT_PCP;
- myProcPid = getpid();
/* call PCP child main */
POOL_SETMASK(&UnBlockSig);
health_check_timer_expired = 0;
close(pipe_fds[1]);
}
- /* Set the process type variable */
- processType = PT_CHILD;
+ SetProcessGlobalVaraibles(PT_CHILD);
/* call child main */
POOL_SETMASK(&UnBlockSig);
close(pipe_fds[1]);
}
- /* Set the process type variable */
- processType = type;
- myProcPid = getpid();
- set_application_name(type);
+ SetProcessGlobalVaraibles(type);
/* call child main */
POOL_SETMASK(&UnBlockSig);
if (pid == 0)
{
on_exit_reset();
- processType = PT_FOLLOWCHILD;
- myProcPid = getpid();
+ SetProcessGlobalVaraibles(PT_FOLLOWCHILD);
ereport(LOG,
(errmsg("start triggering follow command.")));
for (i = 0; i < pool_config->backend_desc->num_backends; i++)
tval = time(NULL);
BACKEND_INFO(backend_id).status_changed_time = tval;
}
-
-/*
- * Application name
- */
-static char *process_application_name = "main";
-
-/*
- * Fixed application names. ordered by ProcessType.
- */
-char *application_names[] = {"main",
- "child",
- "sr_check_worker",
- "heart_beat_sender",
- "heart_beat_receiver",
- "watchdog",
- "life_check",
- "follow_child",
- "watchdog_utility",
- "pcp_main",
- "pcp_child",
- "health_check"
-};
-
-/*
- * Set application name by ProcessType
- */
-void
-set_application_name(ProcessType ptype)
-{
- if (ptype < 0 || ptype >= PT_LAST_PTYPE)
- {
- ereport(ERROR,
- (errmsg("failed to set application name. process type: %d", ptype)));
- }
-
- process_application_name = application_names[ptype];
-
- return;
-}
-
-/*
- * Set application name with arbitrary string. The storage for the string must
- * be persistent at least in the session.
- */
-void
-set_application_name_with_string(char *string)
-{
- process_application_name = string;
-}
-
-/*
- * Set application name with suffix
- */
-void
-set_application_name_with_suffix(ProcessType ptype, int suffix)
-{
- char *appname_buf;
-
- if (ptype < 0 || ptype >= PT_LAST_PTYPE)
- {
- ereport(ERROR,
- (errmsg("failed to set application name. process type: %d", ptype)));
- }
-
- appname_buf = MemoryContextAlloc(TopMemoryContext, POOLCONFIG_MAXNAMELEN);
- snprintf(appname_buf, POOLCONFIG_MAXNAMELEN, "%s%d", application_names[ptype], suffix);
- process_application_name = appname_buf;
-
- return;
-}
-
-/*
- * Get current application name
- */
-char *
-get_application_name(void)
-{
- return process_application_name;
-}
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2010 PgPool Global Development Group
+ * Copyright (c) 2003-2020 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
*
* Global variables. Should be eventually removed.
*/
+#include <unistd.h> /*For getpid*/
#include "pool.h"
+#include "utils/elog.h"
+
pid_t mypid; /* pgpool parent process id */
pid_t myProcPid; /* process pid */
ProcessType processType;
ProcessState processState;
+
+/*
+ * Application name
+ */
+static char *process_application_name = "main";
+
+/*
+ * Fixed application names. ordered by ProcessType.
+ */
+char *application_names[] = {"main",
+ "child",
+ "sr_check_worker",
+ "heart_beat_sender",
+ "heart_beat_receiver",
+ "watchdog",
+ "life_check",
+ "follow_child",
+ "watchdog_utility",
+ "pcp_main",
+ "pcp_child",
+ "health_check"
+};
+
+char *
+get_application_name_for_procees(ProcessType ptype)
+{
+ if (ptype < 0 || ptype >= PT_LAST_PTYPE)
+ {
+ ereport(ERROR,
+ (errmsg("failed to set application name. process type: %d", ptype)));
+ }
+ return application_names[ptype];
+}
+
+/*
+ * Set application name by ProcessType
+ */
+void
+set_application_name(ProcessType ptype)
+{
+ process_application_name = get_application_name_for_procees(ptype);
+}
+
+/*
+ * Set application name with arbitrary string. The storage for the string must
+ * be persistent at least in the session.
+ */
+void
+set_application_name_with_string(char *string)
+{
+ process_application_name = string;
+}
+
+/*
+ * Set application name with suffix
+ */
+void
+set_application_name_with_suffix(ProcessType ptype, int suffix)
+{
+ static char appname_buf[POOLCONFIG_MAXNAMELEN +1];
+ snprintf(appname_buf, POOLCONFIG_MAXNAMELEN, "%s%d", get_application_name_for_procees(ptype), suffix);
+ set_application_name_with_string(appname_buf);
+}
+
+/*
+ * Get current application name
+ */
+char *
+get_application_name(void)
+{
+ return process_application_name;
+}
+
+void SetProcessGlobalVaraibles(ProcessType pType)
+{
+ processType = pType;
+ myProcPid = getpid();
+ set_application_name(pType);
+}
sigjmp_buf local_sigjmp_buf;
struct timeval uptime;
- /* set application name */
- set_application_name(PT_PCP);
-
/* Identify myself via ps */
init_ps_display("", "", "", "");
if (pid == 0) /* child */
{
- /* Set the process type variable */
- processType = PT_PCP_WORKER;
-
- /* set application name */
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_PCP_WORKER);
on_exit_reset();
/* Close the listen sockets sockets */
close(pcp_unix_fd);
close(pcp_inet_fd);
- myProcPid = getpid();
/* call PCP child main */
if (pcp_worker_children)
list_free(pcp_worker_children);
int connections_count = 0; /* used if child_max_connections > 0 */
char psbuf[NI_MAXHOST + 128];
- set_application_name(PT_CHILD);
-
ereport(DEBUG2,
(errmsg("I am Pgpool Child process with pid: %d", getpid())));
md5.c \
base64.c \
pool_passwd.c \
- pool_signal.c \
strlcpy.c \
regex_array.c \
pool_config_variables.c \
pool_config.c \
fe_memutils.c \
- pool_path.c \
- pool_globals.c
+ pool_path.c
DEFS = @DEFS@ \
-DDEFAULT_CONFIGDIR=\"$(sysconfdir)\" -DPOOL_TOOLS
rm -f $@ && ln -s $< .
ssl_utils.h: ../../../src/include/utils/ssl_utils.h
rm -f $@ && ln -s $< .
-pool_signal.c: ../../../src/utils/pool_signal.c
- rm -f $@ && ln -s $< .
strlcpy.c: ../../../src/utils/strlcpy.c
rm -f $@ && ln -s $< .
regex_array.c: ../../../src/utils/regex_array.c
rm -f $@ && ln -s $< .
fe_memutils.c: ../../../src/tools/fe_memutils.c
rm -f $@ && ln -s $< .
-pool_globals.c: ../../../src/main/pool_globals.c
- rm -f $@ && ln -s $< .
clean-local:
-rm -f $(nodist_pg_enc_SOURCES)
am__dirstamp = $(am__leading_dot)dirstamp
dist_pg_enc_OBJECTS = pg_enc.$(OBJEXT) ../fe_port.$(OBJEXT)
nodist_pg_enc_OBJECTS = ssl_utils.$(OBJEXT) md5.$(OBJEXT) \
- base64.$(OBJEXT) pool_passwd.$(OBJEXT) pool_signal.$(OBJEXT) \
- strlcpy.$(OBJEXT) regex_array.$(OBJEXT) \
- pool_config_variables.$(OBJEXT) pool_config.$(OBJEXT) \
- fe_memutils.$(OBJEXT) pool_path.$(OBJEXT) \
- pool_globals.$(OBJEXT)
+ base64.$(OBJEXT) pool_passwd.$(OBJEXT) strlcpy.$(OBJEXT) \
+ regex_array.$(OBJEXT) pool_config_variables.$(OBJEXT) \
+ pool_config.$(OBJEXT) fe_memutils.$(OBJEXT) \
+ pool_path.$(OBJEXT)
pg_enc_OBJECTS = $(dist_pg_enc_OBJECTS) $(nodist_pg_enc_OBJECTS)
pg_enc_LDADD = $(LDADD)
AM_V_lt = $(am__v_lt_@AM_V@)
md5.c \
base64.c \
pool_passwd.c \
- pool_signal.c \
strlcpy.c \
regex_array.c \
pool_config_variables.c \
pool_config.c \
fe_memutils.c \
- pool_path.c \
- pool_globals.c
+ pool_path.c
all: all-am
rm -f $@ && ln -s $< .
ssl_utils.h: ../../../src/include/utils/ssl_utils.h
rm -f $@ && ln -s $< .
-pool_signal.c: ../../../src/utils/pool_signal.c
- rm -f $@ && ln -s $< .
strlcpy.c: ../../../src/utils/strlcpy.c
rm -f $@ && ln -s $< .
regex_array.c: ../../../src/utils/regex_array.c
rm -f $@ && ln -s $< .
fe_memutils.c: ../../../src/tools/fe_memutils.c
rm -f $@ && ln -s $< .
-pool_globals.c: ../../../src/main/pool_globals.c
- rm -f $@ && ln -s $< .
clean-local:
-rm -f $(nodist_pg_enc_SOURCES)
../fe_port.c
nodist_pg_md5_SOURCES = md5.c \
pool_passwd.c \
- pool_signal.c \
strlcpy.c \
regex_array.c \
pool_config_variables.c \
pool_config.c \
- fe_memutils.c \
- pool_globals.c
+ fe_memutils.c
DEFS = @DEFS@ \
-DDEFAULT_CONFIGDIR=\"$(sysconfdir)\" -DPOOL_TOOLS
rm -f $@ && ln -s $< .
pool_passwd.c: ../../../src/auth/pool_passwd.c
rm -f $@ && ln -s $< .
-pool_signal.c: ../../../src/utils/pool_signal.c
- rm -f $@ && ln -s $< .
strlcpy.c: ../../../src/utils/strlcpy.c
rm -f $@ && ln -s $< .
regex_array.c: ../../../src/utils/regex_array.c
rm -f $@ && ln -s $< .
fe_memutils.c: ../../../src/tools/fe_memutils.c
rm -f $@ && ln -s $< .
-pool_globals.c: ../../../src/main/pool_globals.c
- rm -f $@ && ln -s $< .
clean-local:
-rm -f $(nodist_pg_md5_SOURCES)
am__dirstamp = $(am__leading_dot)dirstamp
dist_pg_md5_OBJECTS = pg_md5.$(OBJEXT) ../fe_port.$(OBJEXT)
nodist_pg_md5_OBJECTS = md5.$(OBJEXT) pool_passwd.$(OBJEXT) \
- pool_signal.$(OBJEXT) strlcpy.$(OBJEXT) regex_array.$(OBJEXT) \
+ strlcpy.$(OBJEXT) regex_array.$(OBJEXT) \
pool_config_variables.$(OBJEXT) pool_config.$(OBJEXT) \
- fe_memutils.$(OBJEXT) pool_globals.$(OBJEXT)
+ fe_memutils.$(OBJEXT)
pg_md5_OBJECTS = $(dist_pg_md5_OBJECTS) $(nodist_pg_md5_OBJECTS)
pg_md5_LDADD = $(LDADD)
AM_V_lt = $(am__v_lt_@AM_V@)
nodist_pg_md5_SOURCES = md5.c \
pool_passwd.c \
- pool_signal.c \
strlcpy.c \
regex_array.c \
pool_config_variables.c \
pool_config.c \
- fe_memutils.c \
- pool_globals.c
+ fe_memutils.c
all: all-am
rm -f $@ && ln -s $< .
pool_passwd.c: ../../../src/auth/pool_passwd.c
rm -f $@ && ln -s $< .
-pool_signal.c: ../../../src/utils/pool_signal.c
- rm -f $@ && ln -s $< .
strlcpy.c: ../../../src/utils/strlcpy.c
rm -f $@ && ln -s $< .
regex_array.c: ../../../src/utils/regex_array.c
rm -f $@ && ln -s $< .
fe_memutils.c: ../../../src/tools/fe_memutils.c
rm -f $@ && ln -s $< .
-pool_globals.c: ../../../src/main/pool_globals.c
- rm -f $@ && ln -s $< .
clean-local:
-rm -f $(nodist_pg_md5_SOURCES)
socket_stream.c \
regex_array.c \
psprintf.c \
- md5.c \
- pool_globals.c
+ md5.c
DEFS = @DEFS@ \
-DDEFAULT_CONFIGDIR=\"$(sysconfdir)\" -DPOOL_TOOLS
rm -f $@ && ln -s $< .
fe_memutils.c: ../../../src/tools/fe_memutils.c
rm -f $@ && ln -s $< .
-pool_globals.c: ../../../src/main/pool_globals.c
- rm -f $@ && ln -s $< .
clean-local:
-rm -f $(nodist_wd_cli_SOURCES) $(dist_bin_SCRIPTS)
pool_config_variables.$(OBJEXT) pool_config.$(OBJEXT) \
fe_memutils.$(OBJEXT) stringinfo.$(OBJEXT) strlcpy.$(OBJEXT) \
socket_stream.$(OBJEXT) regex_array.$(OBJEXT) \
- psprintf.$(OBJEXT) md5.$(OBJEXT) pool_globals.$(OBJEXT)
+ psprintf.$(OBJEXT) md5.$(OBJEXT)
wd_cli_OBJECTS = $(dist_wd_cli_OBJECTS) $(nodist_wd_cli_OBJECTS)
wd_cli_LDADD = $(LDADD)
AM_V_lt = $(am__v_lt_@AM_V@)
socket_stream.c \
regex_array.c \
psprintf.c \
- md5.c \
- pool_globals.c
+ md5.c
all: all-am
rm -f $@ && ln -s $< .
fe_memutils.c: ../../../src/tools/fe_memutils.c
rm -f $@ && ln -s $< .
-pool_globals.c: ../../../src/main/pool_globals.c
- rm -f $@ && ln -s $< .
clean-local:
-rm -f $(nodist_wd_cli_SOURCES) $(dist_bin_SCRIPTS)
{
on_exit_reset();
- /* Set the process type variable */
- processType = PT_WATCHDOG;
- myProcPid = getpid();
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_WATCHDOG);
/* call watchdog child main */
POOL_SETMASK(&UnBlockSig);
return pid;
}
on_exit_reset();
- processType = PT_WATCHDOG_UTILITY;
- myProcPid = getpid();
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_WATCHDOG_UTILITY);
POOL_SETMASK(&UnBlockSig);
return pid;
}
on_exit_reset();
- myProcPid = getpid();
- processType = PT_WATCHDOG_UTILITY;
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_WATCHDOG_UTILITY);
POOL_SETMASK(&UnBlockSig);
}
on_exit_reset();
- processType = PT_HB_RECEIVER;
- myProcPid = getpid();
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_HB_RECEIVER);
if (fork_wait_time > 0)
{
}
on_exit_reset();
- myProcPid = getpid();
- processType = PT_HB_SENDER;
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_HB_SENDER);
if (fork_wait_time > 0)
{
if (pid == 0)
{
on_exit_reset();
- processType = PT_WATCHDOG_UTILITY;
- set_application_name(processType);
- myProcPid = getpid();
+ SetProcessGlobalVaraibles(PT_WATCHDOG_UTILITY);
close(STDOUT_FILENO);
dup2(pfd[1], STDOUT_FILENO);
close(pfd[0]);
if (pid == 0)
{
on_exit_reset();
-
- /* Set the process type variable */
- processType = PT_LIFECHECK;
- myProcPid = getpid();
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_LIFECHECK);
/* call lifecheck child main */
POOL_SETMASK(&UnBlockSig);
{
/* CHILD */
on_exit_reset();
- processType = PT_WATCHDOG_UTILITY;
- myProcPid = getpid();
- set_application_name(processType);
+ SetProcessGlobalVaraibles(PT_WATCHDOG_UTILITY);
+
close(STDOUT_FILENO);
dup2(pfd[1], STDOUT_FILENO);
close(pfd[0]);