From: Marko Kreen Date: Sat, 10 Jan 2009 14:52:05 +0000 (+0000) Subject: some more cleanups: X-Git-Tag: pgbouncer_1_3_rc1~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9552a7e3900f10b3b07a8904da5e514c0730c47;p=pgbouncer some more cleanups: - avoid NULL values for config variables - cf_shutdown=2 means fast shutdown - export cf_config_file --- diff --git a/include/bouncer.h b/include/bouncer.h index d4a8c90..4ce833c 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -301,6 +301,7 @@ extern int cf_verbose; extern int cf_daemon; extern int cf_quiet; +extern char *cf_config_file; extern char *cf_jobname; extern int cf_syslog; extern char *cf_syslog_facility; diff --git a/src/admin.c b/src/admin.c index e757474..6d9058e 100644 --- a/src/admin.c +++ b/src/admin.c @@ -797,7 +797,8 @@ static bool admin_cmd_shutdown(PgSocket *admin, const char *arg) * before closing open sockets. */ log_info("SHUTDOWN command issued"); - exit(0); + cf_shutdown = 2; + event_loopbreak(); return true; } diff --git a/src/janitor.c b/src/janitor.c index 8ec9b47..1c6a566 100644 --- a/src/janitor.c +++ b/src/janitor.c @@ -521,9 +521,11 @@ static void do_full_maint(int sock, short flags, void *arg) cleanup_client_logins(); - if (cf_shutdown && get_active_server_count() == 0) { + if (cf_shutdown == 1 && get_active_server_count() == 0) { log_info("server connections dropped, exiting"); - exit(0); + cf_shutdown = 2; + event_loopbreak(); + return; } if (cf_auth_type >= AUTH_TRUST) diff --git a/src/main.c b/src/main.c index 7bb15ce..0f85b1a 100644 --- a/src/main.c +++ b/src/main.c @@ -55,12 +55,12 @@ int cf_quiet = 0; /* if set, no log is printed to stdout/err */ int cf_verbose = 0; int cf_daemon = 0; int cf_pause_mode = P_NONE; -int cf_shutdown = 0; +int cf_shutdown = 0; /* 1 - wait for queries to finish, 2 - shutdown immediately */ int cf_reboot = 0; int cf_syslog = 0; static char *cf_username = ""; char *cf_syslog_facility = "daemon"; -static char *cf_config_file; +char *cf_config_file = ""; char *cf_listen_addr = NULL; int cf_listen_port = 6432; @@ -101,7 +101,8 @@ int cf_server_round_robin = 0; char *cf_ignore_startup_params = ""; -char *cf_autodb_connstr = NULL; +char *cf_autodb_connstr = NULL; /* here is "" different from NULL */ + usec_t cf_autodb_idle_timeout = 3600*USEC; usec_t cf_server_lifetime = 60*60*USEC; @@ -115,8 +116,8 @@ usec_t cf_suspend_timeout = 10*USEC; usec_t g_suspend_start = 0; -char *cf_logfile = NULL; -char *cf_pidfile = NULL; +char *cf_logfile = ""; +char *cf_pidfile = ""; char *cf_jobname = "pgbouncer"; char *cf_admin_users = ""; @@ -426,7 +427,7 @@ static void go_daemon(void) { int pid, fd; - if (!cf_pidfile) + if (!cf_pidfile[0]) fatal("daemon needs pidfile configured"); /* dont log to stdout anymore */ @@ -468,7 +469,7 @@ static void go_daemon(void) static void remove_pidfile(void) { - if (!cf_pidfile) + if (!cf_pidfile[0]) return; unlink(cf_pidfile); } @@ -480,7 +481,7 @@ static void check_pidfile(void) pid_t pid = 0; int fd, res; - if (!cf_pidfile) + if (!cf_pidfile[0]) return; /* check if pidfile exists */ @@ -526,7 +527,7 @@ static void write_pidfile(void) pid_t pid; int res, fd; - if (!cf_pidfile) + if (!cf_pidfile[0]) return; pid = getpid(); @@ -729,7 +730,9 @@ int main(int argc, char *argv[]) write_pidfile(); /* main loop */ - while (1) + while (cf_shutdown < 2) main_loop_once(); + + return 0; } diff --git a/src/util.c b/src/util.c index 6d55831..9e51c56 100644 --- a/src/util.c +++ b/src/util.c @@ -152,7 +152,7 @@ static void _log_write(const char *pfx, const char *msg) len = snprintf(buf, sizeof(buf), "%s %u %s %s\n", tbuf, (unsigned)getpid(), pfx, msg); - if (cf_logfile) + if (cf_logfile[0]) write_logfile(buf, len); if (cf_syslog)