[sheepdog] [PATCH v2] sheepdog:show more detail of the crash source

Wang Zhengyong wangzhengyong at cmss.chinamobile.com
Thu Feb 12 08:44:53 CET 2015


In the current sheepdog, when sheepdog crashed,
there is too little information about the signal source.

This patch use (*handler)(int, siginfo_t *, void *)
instead of (*handler)(int). In this way, can show more detail of the
crash problem, especially the pid of singal sender

Cc: Hitoshi Mitake <mitake.hitoshi at gmail.com>
Signed-off-by: Wang Zhengyong <wangzhengyong at cmss.chinamobile.com>
---
v2: fix the wrong handler assignment
---
 dog/dog.c           |    2 +-
 include/util.h      |    4 ++--
 lib/logger.c        |    4 ++--
 lib/util.c          |   13 ++++++++-----
 sheep/sheep.c       |    9 +++++----
 shepherd/shepherd.c |    2 +-
 6 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/dog/dog.c b/dog/dog.c
index 54520dd..77aa27b 100644
--- a/dog/dog.c
+++ b/dog/dog.c
@@ -368,7 +368,7 @@ static const struct sd_option *build_sd_options(const char *opts)
 	return sd_opts;
 }
 
-static void crash_handler(int signo)
+static void crash_handler(int signo, siginfo_t *info, void *context)
 {
 	sd_err("dog exits unexpectedly (%s).", strsignal(signo));
 
diff --git a/include/util.h b/include/util.h
index 6a513e0..3c34b40 100644
--- a/include/util.h
+++ b/include/util.h
@@ -108,8 +108,8 @@ int rmdir_r(const char *dir_path);
 int purge_directory(const char *dir_path);
 bool is_numeric(const char *p);
 const char *data_to_str(void *data, size_t data_length);
-int install_sighandler(int signum, void (*handler)(int), bool once);
-int install_crash_handler(void (*handler)(int));
+int install_sighandler(int signum, void (*handler)(int, siginfo_t *, void *), bool once);
+int install_crash_handler(void (*handler)(int, siginfo_t *, void *));
 void reraise_crash_signal(int signo, int status);
 pid_t gettid(void);
 int tkill(int tid, int sig);
diff --git a/lib/logger.c b/lib/logger.c
index 02bab00..da0ebac 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -531,7 +531,7 @@ static bool is_sheep_dead(int signo)
 	return signo == SIGHUP;
 }
 
-static void crash_handler(int signo)
+static void crash_handler(int signo, siginfo_t *info, void *context)
 {
 	if (is_sheep_dead(signo))
 		sd_err("sheep pid %d exited unexpectedly.", sheep_pid);
@@ -552,7 +552,7 @@ static void crash_handler(int signo)
 	reraise_crash_signal(signo, 1);
 }
 
-static void sighup_handler(int signo)
+static void sighup_handler(int signo, siginfo_t *info, void *context)
 {
 	rotate_log();
 }
diff --git a/lib/util.c b/lib/util.c
index 21e0143..e217629 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -524,25 +524,28 @@ const char *data_to_str(void *data, size_t data_length)
  * If 'once' is true, the signal will be restored to the default state
  * after 'handler' is called.
  */
-int install_sighandler(int signum, void (*handler)(int), bool once)
+int install_sighandler(int signum, void (*handler)(int, siginfo_t *, void *), bool once)
 {
 	struct sigaction sa = {};
 
-	sa.sa_handler = handler;
+	sa.sa_sigaction = handler;
+	sa.sa_flags = SA_SIGINFO;
+
 	if (once)
-		sa.sa_flags = SA_RESETHAND | SA_NODEFER;
+		sa.sa_flags = sa.sa_flags | SA_RESETHAND | SA_NODEFER;
 	sigemptyset(&sa.sa_mask);
 
 	return sigaction(signum, &sa, NULL);
 }
 
-int install_crash_handler(void (*handler)(int))
+int install_crash_handler(void (*handler)(int, siginfo_t *, void *))
 {
 	return install_sighandler(SIGSEGV, handler, true) ||
 		install_sighandler(SIGABRT, handler, true) ||
 		install_sighandler(SIGBUS, handler, true) ||
 		install_sighandler(SIGILL, handler, true) ||
-		install_sighandler(SIGFPE, handler, true);
+		install_sighandler(SIGFPE, handler, true) ||
+		install_sighandler(SIGQUIT, handler, true);
 }
 
 /*
diff --git a/sheep/sheep.c b/sheep/sheep.c
index e0a034f..6c540ae 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -239,7 +239,7 @@ static void signal_handler(int listen_fd, int events, void *data)
 
 	ret = read(sigfd, &siginfo, sizeof(siginfo));
 	assert(ret == sizeof(siginfo));
-	sd_debug("signal %d", siginfo.ssi_signo);
+	sd_debug("signal %d, ssi pid %d", siginfo.ssi_signo, siginfo.ssi_pid);
 	switch (siginfo.ssi_signo) {
 	case SIGTERM:
 		sys->cinfo.status = SD_STATUS_KILLED;
@@ -276,9 +276,10 @@ static int init_signal(void)
 	return 0;
 }
 
-static void crash_handler(int signo)
+static void crash_handler(int signo, siginfo_t *info, void *context)
 {
-	sd_emerg("sheep exits unexpectedly (%s).", strsignal(signo));
+	sd_emerg("sheep exits unexpectedly (%s), si pid %d, uid %d, errno %d, code %d",
+		strsignal(signo), info->si_pid, info->si_uid, info->si_errno, info->si_code);
 
 	sd_backtrace();
 	sd_dump_variable(__sys);
@@ -639,7 +640,7 @@ end:
 	return status;
 }
 
-static void sighup_handler(int signum)
+static void sighup_handler(int signo, siginfo_t *info, void *context)
 {
 	if (unlikely(logger_pid == -1))
 		return;
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index fd59229..dc6df74 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -637,7 +637,7 @@ static int set_listen_fd_cb(int fd, void *data)
 	return 0;
 }
 
-static void crash_handler(int signo)
+static void crash_handler(int signo, siginfo_t *info, void *context)
 {
 	sd_emerg("shepherd exits unexpectedly (%s).", strsignal(signo));
 
-- 
1.7.1






More information about the sheepdog mailing list