pgpool2.git / summary / log / commit / refs

commit    9c298510eced5bf471e5bdc567b09e765d0b332f
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Sun Jan 25 10:14:31 2009 +0000

    Add pid_file_name directive


main.c | 18 ++++++------------ pgpool.conf.sample | 5 +++++ pool.h | 3 ++- pool_config.c | 21 ++++++++++++++++++++- pool_config.l | 21 ++++++++++++++++++++- 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 614dcfa2f..54017b850 100644 --- a/main.c +++ b/main.c @@ -708,11 +708,9 @@ static void stop_me(void) static int read_pid_file(void) { FILE *fd; - char path[POOLMAXPATHLEN]; char pidbuf[128]; - snprintf(path, sizeof(path), "%s/%s", pool_config->logdir, PID_FILE_NAME); - fd = fopen(path, "r"); + fd = fopen(pool_config->pid_file_name, "r"); if (!fd) { return -1; @@ -720,7 +718,7 @@ static int read_pid_file(void) if (fread(pidbuf, 1, sizeof(pidbuf), fd) <= 0) { pool_error("could not read pid file as %s. reason: %s", - path, strerror(errno)); + pool_config->pid_file_name, strerror(errno)); fclose(fd); return -1; } @@ -734,15 +732,13 @@ static int read_pid_file(void) static void write_pid_file(void) { FILE *fd; - char path[POOLMAXPATHLEN]; char pidbuf[128]; - snprintf(path, sizeof(path), "%s/%s", pool_config->logdir, PID_FILE_NAME); - fd = fopen(path, "w"); + fd = fopen(pool_config->pid_file_name, "w"); if (!fd) { pool_error("could not open pid file as %s. reason: %s", - path, strerror(errno)); + pool_config->pid_file_name, strerror(errno)); pool_shmem_exit(1); exit(1); } @@ -751,7 +747,7 @@ static void write_pid_file(void) if (fclose(fd)) { pool_error("could not write pid file as %s. reason: %s", - path, strerror(errno)); + pool_config->pid_file_name, strerror(errno)); pool_shmem_exit(1); exit(1); } @@ -945,7 +941,6 @@ static void myunlink(const char* path) static void myexit(int code) { - char path[POOLMAXPATHLEN]; int i; if (getpid() != mypid) @@ -971,8 +966,7 @@ static void myexit(int code) myunlink(un_addr.sun_path); myunlink(pcp_un_addr.sun_path); - snprintf(path, sizeof(path), "%s/%s", pool_config->logdir, PID_FILE_NAME); - myunlink(path); + myunlink(pool_config->pid_file_name); pool_shmem_exit(code); exit(code); diff --git a/pgpool.conf.sample b/pgpool.conf.sample index e44992de9..bb66d059a 100644 --- a/pgpool.conf.sample +++ b/pgpool.conf.sample @@ -56,6 +56,9 @@ authentication_timeout = 60 # Logging directory logdir = '/tmp' +# pid file name +pid_file_name = '/var/run/pgpool/pgpool.pid' + # Replication mode replication_mode = false @@ -73,6 +76,8 @@ replicate_select = false # Semicolon separated list of queries to be issued at the end of a session reset_query_list = 'ABORT; RESET ALL; SET SESSION AUTHORIZATION DEFAULT' +# for 8.3 or newer PostgreSQL versions following is recommended. +# reset_query_list = 'ABORT; DISCARD ALL' # If true print timestamp on each log line. print_timestamp = true diff --git a/pool.h b/pool.h index 48646afd0..a286d4613 100644 --- a/pool.h +++ b/pool.h @@ -56,7 +56,7 @@ #define DEFAULT_SOCKET_DIR "/tmp" /* pid file name */ -#define PID_FILE_NAME "pgpool.pid" +#define DEFAULT_PID_FILE_NAME "/var/run/pgpool/pgpool.pid" typedef enum { POOL_CONTINUE = 0, @@ -134,6 +134,7 @@ typedef struct { int authentication_timeout; /* maximum time in seconds to complete client authentication */ int max_pool; /* max # of connection pool per child */ char *logdir; /* logging directory */ + char *pid_file_name; /* pid file name */ char *backend_socket_dir; /* Unix domain socket directory for the PostgreSQL server */ int replication_mode; /* replication mode */ diff --git a/pool_config.c b/pool_config.c index dc460f565..cfa0f6a8d 100644 --- a/pool_config.c +++ b/pool_config.c @@ -404,7 +404,7 @@ char *yytext; * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2008 PgPool Global Development Group + * Copyright (c) 2003-2009 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -1674,6 +1674,7 @@ int pool_init_config(void) pool_config->child_max_connections = 0; pool_config->authentication_timeout = 60; pool_config->logdir = DEFAULT_LOGDIR; + pool_config->pid_file_name = DEFAULT_PID_FILE_NAME; pool_config->log_statement = 0; pool_config->log_connections = 0; pool_config->log_hostname = 0; @@ -1993,6 +1994,24 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) } pool_config->logdir = str; } + else if (!strcmp(key, "pid_file_name") && CHECK_CONTEXT(INIT_CONFIG, context)) + { + char *str; + + if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY) + { + PARSE_ERROR(); + fclose(fd); + return(-1); + } + str = extract_string(yytext, token); + if (str == NULL) + { + fclose(fd); + return(-1); + } + pool_config->pid_file_name = str; + } else if (!strcmp(key, "log_connections") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) { diff --git a/pool_config.l b/pool_config.l index 33006e39b..da652aaf9 100644 --- a/pool_config.l +++ b/pool_config.l @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2008 PgPool Global Development Group + * Copyright (c) 2003-2009 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -136,6 +136,7 @@ int pool_init_config(void) pool_config->child_max_connections = 0; pool_config->authentication_timeout = 60; pool_config->logdir = DEFAULT_LOGDIR; + pool_config->pid_file_name = DEFAULT_PID_FILE_NAME; pool_config->log_statement = 0; pool_config->log_connections = 0; pool_config->log_hostname = 0; @@ -455,6 +456,24 @@ int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context) } pool_config->logdir = str; } + else if (!strcmp(key, "pid_file_name") && CHECK_CONTEXT(INIT_CONFIG, context)) + { + char *str; + + if (token != POOL_STRING && token != POOL_UNQUOTED_STRING && token != POOL_KEY) + { + PARSE_ERROR(); + fclose(fd); + return(-1); + } + str = extract_string(yytext, token); + if (str == NULL) + { + fclose(fd); + return(-1); + } + pool_config->pid_file_name = str; + } else if (!strcmp(key, "log_connections") && CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context)) { [parent: 3da583d9146f]