Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
524b2626
Commit
524b2626
authored
Mar 26, 2014
by
Matt Stancliff
Committed by
antirez
Aug 27, 2014
Browse files
Add graceful exit when Ctrl-C is received
parent
78bde472
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis.c
View file @
524b2626
...
@@ -3103,10 +3103,21 @@ void redisAsciiArt(void) {
...
@@ -3103,10 +3103,21 @@ void redisAsciiArt(void) {
zfree
(
buf
);
zfree
(
buf
);
}
}
static
void
sigtermHandler
(
int
sig
)
{
static
void
sigShutdownHandler
(
int
sig
)
{
REDIS_NOTUSED
(
sig
);
char
*
msg
;
redisLogFromHandler
(
REDIS_WARNING
,
"Received SIGTERM, scheduling shutdown..."
);
switch
(
sig
)
{
case
SIGINT
:
msg
=
"Received SIGINT scheduling shutdown..."
;
break
;
case
SIGTERM
:
msg
=
"Received SIGTERM scheduling shutdown..."
;
break
;
default:
msg
=
"Received shutdown signal, scheduling shutdown..."
;
};
redisLogFromHandler
(
REDIS_WARNING
,
msg
);
server
.
shutdown_asap
=
1
;
server
.
shutdown_asap
=
1
;
}
}
...
@@ -3117,8 +3128,9 @@ void setupSignalHandlers(void) {
...
@@ -3117,8 +3128,9 @@ void setupSignalHandlers(void) {
* Otherwise, sa_handler is used. */
* Otherwise, sa_handler is used. */
sigemptyset
(
&
act
.
sa_mask
);
sigemptyset
(
&
act
.
sa_mask
);
act
.
sa_flags
=
0
;
act
.
sa_flags
=
0
;
act
.
sa_handler
=
sig
term
Handler
;
act
.
sa_handler
=
sig
Shutdown
Handler
;
sigaction
(
SIGTERM
,
&
act
,
NULL
);
sigaction
(
SIGTERM
,
&
act
,
NULL
);
signal
(
SIGINT
,
sigShutdownHandler
);
#ifdef HAVE_BACKTRACE
#ifdef HAVE_BACKTRACE
sigemptyset
(
&
act
.
sa_mask
);
sigemptyset
(
&
act
.
sa_mask
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment