Log crashes and unexpected signals as FATAL

This commit is contained in:
Jeremy Lakeman 2013-07-31 14:51:24 +09:30
parent 629bfbffd3
commit 6c85999917
6 changed files with 25 additions and 24 deletions

View File

@ -1120,8 +1120,6 @@ int app_config_schema(const struct cli_parsed *parsed, struct cli_context *conte
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
if (create_serval_instance_dir() == -1)
return -1;
struct cf_om_node *root = NULL;
if (cf_sch_config_main(&root) == -1) {
cf_om_free_node(&root);

12
log.c
View File

@ -755,7 +755,7 @@ ssize_t get_self_executable_path(char *buf, size_t len)
#endif
}
int log_backtrace(struct __sourceloc whence)
int log_backtrace(int level, struct __sourceloc whence)
{
#ifndef NO_BACKTRACE
_log_iterator it;
@ -812,7 +812,7 @@ int log_backtrace(struct __sourceloc whence)
}
// parent
close(stdout_fds[1]);
_log_iterator_printf_nl(&it, LOG_LEVEL_DEBUG, whence, "GDB BACKTRACE");
_log_iterator_printf_nl(&it, level, whence, "GDB BACKTRACE");
char buf[1024];
char *const bufe = buf + sizeof buf;
char *linep = buf;
@ -824,14 +824,14 @@ int log_backtrace(struct __sourceloc whence)
for (; p < readp; ++p)
if (*p == '\n' || *p == '\0') {
*p = '\0';
_log_iterator_printf_nl(&it, LOG_LEVEL_DEBUG, __NOWHERE__, "%s", linep);
_log_iterator_printf_nl(&it, level, __NOWHERE__, "%s", linep);
linep = p + 1;
}
if (readp >= bufe && linep == buf) {
// Line does not fit into buffer.
char t = bufe[-1];
bufe[-1] = '\0';
_log_iterator_printf_nl(&it, LOG_LEVEL_DEBUG, __NOWHERE__, "%s", buf);
_log_iterator_printf_nl(&it, level, __NOWHERE__, "%s", buf);
buf[0] = t;
readp = buf + 1;
} else if (readp + 120 >= bufe && linep != buf) {
@ -847,7 +847,7 @@ int log_backtrace(struct __sourceloc whence)
WHY_perror("read");
if (readp > linep) {
*readp = '\0';
_log_iterator_printf_nl(&it, LOG_LEVEL_DEBUG, __NOWHERE__, "%s", linep);
_log_iterator_printf_nl(&it, level, __NOWHERE__, "%s", linep);
}
close(stdout_fds[0]);
int status = 0;
@ -855,7 +855,7 @@ int log_backtrace(struct __sourceloc whence)
WHY_perror("waitpid");
strbuf b = strbuf_local(buf, sizeof buf);
strbuf_append_exit_status(b, status);
_log_iterator_printf_nl(&it, LOG_LEVEL_DEBUG, __NOWHERE__, "gdb %s", buf);
_log_iterator_printf_nl(&it, level, __NOWHERE__, "gdb %s", buf);
unlink(tempfile);
#endif
return 0;

4
log.h
View File

@ -106,7 +106,7 @@ void vlogMessage(int level, struct __sourceloc whence, const char *fmt, va_list)
void logConfigChanged();
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len);
ssize_t get_self_executable_path(char *buf, size_t len);
int log_backtrace(struct __sourceloc whence);
int log_backtrace(int level, struct __sourceloc whence);
struct strbuf;
#define __HERE__ ((struct __sourceloc){ .file = __FILE__, .line = __LINE__, .function = __FUNCTION__ })
@ -158,6 +158,6 @@ struct strbuf;
#define dump(X,A,N) logDump(LOG_LEVEL_DEBUG, __WHENCE__, (X), (const unsigned char *)(A), (size_t)(N))
#define BACKTRACE log_backtrace(__WHENCE__)
#define BACKTRACE log_backtrace(LOG_LEVEL_FATAL, __WHENCE__)
#endif // __SERVALD_LOG_H

View File

@ -198,12 +198,12 @@ void fd_periodicstats(struct sched_ent *alarm)
schedule(alarm);
}
void dump_stack()
void dump_stack(int log_level)
{
struct call_stats *call = current_call;
while(call){
if (call->totals)
INFOF("%s",call->totals->name);
LOGF(log_level, "%s",call->totals->name);
call=call->prev;
}
}

View File

@ -782,7 +782,7 @@ int fd_showstats();
int fd_checkalarms();
int fd_func_enter(struct __sourceloc __whence, struct call_stats *this_call);
int fd_func_exit(struct __sourceloc __whence, struct call_stats *this_call);
void dump_stack();
void dump_stack(int log_level);
#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0}; \
struct call_stats _this_call={.totals=&_aggregate_stats}; \

View File

@ -357,12 +357,6 @@ static void signame(char *buf, size_t len, int signal)
void signal_handler(int signal)
{
char buf[80];
signame(buf, sizeof(buf), signal);
INFOF("Caught %s", buf);
WHYF("The following clue may help: %s",crash_handler_clue);
dump_stack();
switch (signal) {
case SIGHUP:
case SIGINT:
@ -370,10 +364,18 @@ void signal_handler(int signal)
rather than here, so we first try to tell the mainline code to do so. If, however, this is
not the first time we have been asked to shut down, then we will do it here. */
server_shutdown_check(NULL);
WHY("Asking Serval process to shutdown cleanly");
INFO("Attempting clean shutdown");
servalShutdown = 1;
return;
}
char buf[80];
signame(buf, sizeof(buf), signal);
LOGF(LOG_LEVEL_FATAL, "Caught signal %s", buf);
LOGF(LOG_LEVEL_FATAL, "The following clue may help: %s",crash_handler_clue);
dump_stack(LOG_LEVEL_FATAL);
serverCleanUp();
exit(0);
}
@ -383,9 +385,10 @@ void crash_handler(int signal)
{
char buf[80];
signame(buf, sizeof(buf), signal);
WHYF("Caught %s", buf);
WHYF("The following clue may help: %s",crash_handler_clue);
dump_stack();
LOGF(LOG_LEVEL_FATAL, "Caught signal %s", buf);
LOGF(LOG_LEVEL_FATAL, "The following clue may help: %s",crash_handler_clue);
dump_stack(LOG_LEVEL_FATAL);
BACKTRACE;
if (config.server.respawn_on_crash) {
int i;
@ -411,7 +414,7 @@ void crash_handler(int signal)
// If that didn't work, then die normally.
INFOF("exit(%d)", -signal);
exit(-signal);
}
}
int getKeyring(char *backing_file)
{