X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/a510cb0c03eac3e3222641860f6dd84bb495c431..36c17a53b6aece050b79b667fd32064f6eb116c2:/src/redis.c?ds=inline diff --git a/src/redis.c b/src/redis.c index c0dac05f..2fd3ee39 100644 --- a/src/redis.c +++ b/src/redis.c @@ -589,13 +589,31 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { pid_t pid; if ((pid = wait3(&statloc,WNOHANG,NULL)) != 0) { + int exitcode = WEXITSTATUS(statloc); + int bysignal = 0; + + if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc); + if (pid == server.bgsavechildpid) { - backgroundSaveDoneHandler(statloc); + backgroundSaveDoneHandler(exitcode,bysignal); } else { - backgroundRewriteDoneHandler(statloc); + backgroundRewriteDoneHandler(exitcode,bysignal); } updateDictResizePolicy(); } + if (server.bgsavethread != (pthread_t) -1) { + int state; + + pthread_mutex_lock(&server.bgsavethread_mutex); + state = server.bgsavethread_state; + pthread_mutex_unlock(&server.bgsavethread_mutex); + + if (state == REDIS_BGSAVE_DONE_OK || state == REDIS_BGSAVE_DONE_ERR) + { + backgroundSaveDoneHandler( + (state == REDIS_BGSAVE_DONE_OK) ? 0 : 1, 0); + } + } } else if (!server.ds_enabled) { /* If there is not a background saving in progress check if * we have to save now */ @@ -867,6 +885,8 @@ void initServer() { server.cronloops = 0; server.bgsavechildpid = -1; server.bgrewritechildpid = -1; + server.bgsavethread_state = REDIS_BGSAVE_THREAD_UNACTIVE; + server.bgsavethread = (pthread_t) -1; server.bgrewritebuf = sdsempty(); server.aofbuf = sdsempty(); server.lastsave = time(NULL);