Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
be4f8ccc
Commit
be4f8ccc
authored
Mar 28, 2012
by
antirez
Browse files
Log from signal handlers is now safer.
parent
f3e159bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/debug.c
View file @
be4f8ccc
...
...
@@ -682,25 +682,16 @@ void watchdogSignalHandler(int sig, siginfo_t *info, void *secret) {
REDIS_NOTUSED
(
info
);
REDIS_NOTUSED
(
sig
);
sds
st
,
log
;
time_t
now
=
time
(
NULL
);
char
date
[
128
];
FILE
*
fp
;
fp
=
(
server
.
logfile
==
NULL
)
?
stdout
:
fopen
(
server
.
logfile
,
"a"
);
if
(
fp
==
NULL
)
return
;
strftime
(
date
,
sizeof
(
date
),
"%d %b %H:%M:%S"
,
localtime
(
&
now
));
log
=
sdscatprintf
(
sdsempty
(),
"
\n
--- WATCHDOG TIMER EXPIRED (%s) ---
\n
"
,
date
);
log
=
sdsnew
(
"
\n
--- WATCHDOG TIMER EXPIRED ---
\n
"
);
#ifdef HAVE_BACKTRACE
st
=
getStackTrace
(
uc
);
#else
st
=
sdsnew
(
"Sorry: no support for backtrace().
\n
"
);
#endif
log
=
sdscatsds
(
log
,
st
);
log
=
sdscat
(
log
,
"------
\n\n
"
);
fprintf
(
fp
,
"%s"
,
log
);
if
(
server
.
logfile
)
fclose
(
fp
);
log
=
sdscat
(
log
,
"------
\n
"
);
redisLogFromHandler
(
REDIS_WARNING
,
log
);
sdsfree
(
st
);
sdsfree
(
log
);
}
...
...
src/redis.c
View file @
be4f8ccc
...
...
@@ -291,6 +291,34 @@ void redisLog(int level, const char *fmt, ...) {
redisLogRaw
(
level
,
msg
);
}
/* Log a fixed message without printf-alike capabilities, in a way that is
* safe to call from a signal handler.
*
* We actually use this only for signals that are not fatal from the point
* of view of Redis. Signals that are going to kill the server anyway and
* where we need printf-alike features are served by redisLog(). */
void
redisLogFromHandler
(
int
level
,
const
char
*
msg
)
{
int
fd
;
char
buf
[
64
];
if
((
level
&
0xff
)
<
server
.
verbosity
||
(
server
.
logfile
==
NULL
&&
server
.
daemonize
))
return
;
fd
=
server
.
logfile
?
open
(
server
.
logfile
,
O_APPEND
|
O_CREAT
|
O_WRONLY
,
0644
)
:
STDIN_FILENO
;
if
(
fd
==
-
1
)
return
;
ll2string
(
buf
,
sizeof
(
buf
),
getpid
());
write
(
fd
,
"["
,
1
);
write
(
fd
,
buf
,
strlen
(
buf
));
write
(
fd
,
" | signal handler] ("
,
20
);
ll2string
(
buf
,
sizeof
(
buf
),
time
(
NULL
));
write
(
fd
,
buf
,
strlen
(
buf
));
write
(
fd
,
") "
,
2
);
write
(
fd
,
msg
,
strlen
(
msg
));
write
(
fd
,
"
\n
"
,
1
);
close
(
fd
);
}
/* Redis generally does not try to recover from out of memory conditions
* when allocating objects or strings, it is not clear if it will be possible
* to report this condition to the client since the networking layer itself
...
...
@@ -2231,7 +2259,7 @@ void redisAsciiArt(void) {
static
void
sigtermHandler
(
int
sig
)
{
REDIS_NOTUSED
(
sig
);
redisLog
(
REDIS_WARNING
,
"Received SIGTERM, scheduling shutdown..."
);
redisLog
FromHandler
(
REDIS_WARNING
,
"Received SIGTERM, scheduling shutdown..."
);
server
.
shutdown_asap
=
1
;
}
...
...
src/redis.h
View file @
be4f8ccc
...
...
@@ -870,6 +870,7 @@ void alsoPropagate(struct redisCommand *cmd, int dbid, robj **argv, int argc, in
int
prepareForShutdown
();
void
redisLog
(
int
level
,
const
char
*
fmt
,
...);
void
redisLogRaw
(
int
level
,
const
char
*
msg
);
void
redisLogFromHandler
(
int
level
,
const
char
*
msg
);
void
usage
();
void
updateDictResizePolicy
(
void
);
int
htNeedsResize
(
dict
*
dict
);
...
...
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