Skip to content
Browse files

Enhance SIGINT handler.

  • Loading branch information...
1 parent 49ac541 commit 5d7bed6d46692a7679d723a2314e6977172febaf t-ishii committed Dec 2, 2009
Showing with 31 additions and 20 deletions.
  1. +26 −18 child.c
  2. +2 −1 pool.h
  3. +3 −1 pool_process_query.c
View
44 child.c
@@ -1,6 +1,6 @@
/* -*-pgsql-c-*- */
/*
- * $Header: /cvsroot/pgpool/pgpool-II/child.c,v 1.36 2009/11/14 13:22:32 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/child.c,v 1.37 2009/12/02 14:19:56 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -74,7 +74,7 @@ static void connection_count_down(void);
/*
* non 0 means SIGTERM(smart shutdown) or SIGINT(fast shutdown) has arrived
*/
-static int exit_request;
+volatile sig_atomic_t exit_request = 0;
static int idle; /* non 0 means this child is in idle state */
static int accepted = 0;
@@ -174,11 +174,7 @@ void do_child(int unix_fd, int inet_fd)
StartupPacket *sp;
/* pgpool stop request already sent? */
- if (exit_request)
- {
- die(0);
- child_exit(0);
- }
+ check_stop_request();
idle = 1;
accepted = 0;
@@ -1211,37 +1207,30 @@ static POOL_CONNECTION_POOL *connect_backend(StartupPacket *sp, POOL_CONNECTION
}
/*
- * signal handler for SIGINT and SIGQUUT
+ * signal handler for SIGTERM, SIGINT and SIGQUUT
*/
static RETSIGTYPE die(int sig)
{
- exit_request = 1;
+ pool_debug("child received shutdown request signal %d", sig);
- pool_debug("child receives shutdown request signal %d", sig);
+ exit_request = sig;
switch (sig)
{
case SIGTERM: /* smart shutdown */
if (idle == 0)
{
pool_debug("child receives smart shutdown request but it's not in idle state");
- return;
}
break;
case SIGINT: /* fast shutdown */
case SIGQUIT: /* immediate shutdown */
- child_exit(0);
break;
default:
+ pool_error("die() received unknown signal: %d", sig);
break;
}
-
- /*
- * child_exit() does this. So we don't need it.
- * send_frontend_exits();
- */
- child_exit(0);
}
/*
@@ -1862,3 +1851,22 @@ static RETSIGTYPE reload_config_handler(int sig)
{
got_sighup = 1;
}
+
+/*
+ * Exit myself if SIGTERM, SIGINT or SIGQUIT has been sent
+ */
+void check_stop_request(void)
+{
+ /*
+ * If smart shutdown was requested but we are not in idle state,
+ * do not exit
+ */
+ if (exit_request == SIGTERM && idle == 0)
+ return;
+
+ if (exit_request)
+ {
+ reset_variables();
+ child_exit(0);
+ }
+}
View
3 pool.h
@@ -1,7 +1,7 @@
/* -*-pgsql-c-*- */
/*
*
- * $Header: /cvsroot/pgpool/pgpool-II/pool.h,v 1.45 2009/11/15 08:27:35 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool.h,v 1.46 2009/12/02 14:19:56 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -650,6 +650,7 @@ extern void finish_recovery(void);
extern void pool_set_nonblock(int fd);
extern void pool_unset_nonblock(int fd);
extern void cancel_request(CancelPacket *sp);
+extern void check_stop_request(void);
/* pool_process_query.c */
void free_select_result(POOL_SELECT_RESULT *result);
View
4 pool_process_query.c
@@ -1,6 +1,6 @@
/* -*-pgsql-c-*- */
/*
- * $Header: /cvsroot/pgpool/pgpool-II/pool_process_query.c,v 1.176 2009/11/29 11:56:59 t-ishii Exp $
+ * $Header: /cvsroot/pgpool/pgpool-II/pool_process_query.c,v 1.177 2009/12/02 14:19:56 t-ishii Exp $
*
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
@@ -150,6 +150,8 @@ POOL_STATUS pool_process_query(POOL_CONNECTION *frontend,
}
+ check_stop_request();
+
/*
* if all backends do not have any pending data in the
* receiving data cache, then issue select(2) to wait for new

0 comments on commit 5d7bed6

Please sign in to comment.
Something went wrong with that request. Please try again.