summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-08-07 16:32:50 +0200
committerantirez <antirez@gmail.com>2014-08-07 16:39:02 +0200
commit7bb25f8a46cafee90ba927d98141ccfa57e190df (patch)
treeae527fa6c810085992c523e23456eb2ed044211b
parentd99a7246f805f20a99bd2fa428c10a64433e6e81 (diff)
downloadredis-7bb25f8a46cafee90ba927d98141ccfa57e190df.tar.gz
Force quit when receiving a second SIGINT.
Also quit ASAP when we are still loading a DB, since care is not needed in this special condition, especially for a SIGINT.
-rw-r--r--src/rdb.c2
-rw-r--r--src/redis.c14
2 files changed, 14 insertions, 2 deletions
diff --git a/src/rdb.c b/src/rdb.c
index ce5f99c9a..2d6ac85fc 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -766,7 +766,7 @@ int rdbSaveBackground(char *filename) {
void rdbRemoveTempFile(pid_t childpid) {
char tmpfile[256];
- snprintf(tmpfile,256,"temp-%d.rdb", (int) childpid);
+ snprintf(tmpfile,sizeof(tmpfile),"temp-%d.rdb", (int) childpid);
unlink(tmpfile);
}
diff --git a/src/redis.c b/src/redis.c
index faed67331..c5c3f79bb 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -3413,6 +3413,18 @@ static void sigShutdownHandler(int sig) {
msg = "Received shutdown signal, scheduling shutdown...";
};
+ /* SIGINT is often delivered via Ctrl+C in an interactive session.
+ * If we receive the signal the second time, we interpret this as
+ * the user really wanting to quit ASAP without waiting to persist
+ * on disk. */
+ if (server.shutdown_asap && sig == SIGINT) {
+ redisLogFromHandler(REDIS_WARNING, "You insist... exiting now.");
+ rdbRemoveTempFile(getpid());
+ exit(1); /* Exit with an error since this was not a clean shutdown. */
+ } else if (server.loading) {
+ exit(0);
+ }
+
redisLogFromHandler(REDIS_WARNING, msg);
server.shutdown_asap = 1;
}
@@ -3426,7 +3438,7 @@ void setupSignalHandlers(void) {
act.sa_flags = 0;
act.sa_handler = sigShutdownHandler;
sigaction(SIGTERM, &act, NULL);
- signal(SIGINT, sigShutdownHandler);
+ sigaction(SIGINT, &act, NULL);
#ifdef HAVE_BACKTRACE
sigemptyset(&act.sa_mask);