From a57dc0d618a2344280209c2ee3f4204f637af7ae Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja@tarantool.org>
Date: Thu, 15 Aug 2013 20:54:17 +0400
Subject: [PATCH] Ignore SIGUSR1 and SIGUSR2 in spawner and replication
 processes.

Be more verbose when exiting the spawner.
---
 src/replication.cc | 45 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/src/replication.cc b/src/replication.cc
index c7173bc5d8..747a7d4ddc 100644
--- a/src/replication.cc
+++ b/src/replication.cc
@@ -290,9 +290,9 @@ replication_send_socket(ev_io *watcher, int events __attribute__((unused)))
 }
 
 
-/*-----------------------------------------------------------------------------*/
-/* spawner process                                                             */
-/*-----------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*
+ * spawner process                                                          *
+ * -------------------------------------------------------------------------*/
 
 /** Initialize the spawner. */
 
@@ -336,6 +336,21 @@ spawner_init(int sock)
 	if (sigaction(SIGCHLD, &sa, NULL) == -1)
 		say_syserror("sigaction");
 
+	sa.sa_handler = SIG_IGN;
+	/*
+	 * Ignore SIGUSR1, SIGUSR1 is used to make snapshots,
+	 * and if someone wrote a faulty regexp for `ps' and
+	 * fed it to `kill' the replication shouldn't die.
+	 */
+	if (sigaction(SIGUSR1, &sa, NULL) == -1)
+		say_syserror("sigaction");
+	/*
+	 * Ignore SIGUSR2 as well, since one can be pretty
+	 * inventive in ways of shooting oneself in the foot.
+	 */
+	if (sigaction(SIGUSR2, &sa, NULL) == -1)
+		say_syserror("sigaction");
+
 	say_crit("initialized");
 	spawner_main_loop();
 }
@@ -397,6 +412,15 @@ spawner_main_loop()
 static void
 spawner_shutdown()
 {
+	/*
+	 * There is no need to ever use signals with the spawner
+	 * process. If someone did send spawner a signal by
+	 * mistake, at least make a squeak in the error log before
+	 * dying.
+	 */
+	if (spawner.killed)
+		say_info("Terminated by signal %d", (int) spawner.killed);
+
 	/* close socket */
 	close(spawner.sock);
 
@@ -612,10 +636,23 @@ replication_relay_loop(int client_sock)
 	    sigaction(SIGTERM, &sa, NULL) == -1)
 		say_syserror("sigaction");
 
-	/* Block SIGPIPE, we already handle EPIPE. */
+	/* Ignore SIGPIPE, we already handle EPIPE. */
 	sa.sa_handler = SIG_IGN;
 	if (sigaction(SIGPIPE, &sa, NULL) == -1)
 		say_syserror("sigaction");
+	/*
+	 * Ignore SIGUSR1, SIGUSR1 is used to make snapshots,
+	 * and if someone wrote a faulty regexp for `ps' and
+	 * fed it to `kill' the replication shouldn't die.
+	 */
+	if (sigaction(SIGUSR1, &sa, NULL) == -1)
+		say_syserror("sigaction");
+	/*
+	 * Ignore SIGUSR2 as well, since one can be pretty
+	 * inventive in ways of shooting oneself in the foot.
+	 */
+	if (sigaction(SIGUSR2, &sa, NULL) == -1)
+		say_syserror("sigaction");
 
 	r = read(client_sock, &lsn, sizeof(lsn));
 	if (r != sizeof(lsn)) {
-- 
GitLab