[PATCH v2 11/14] Log safely in fatal signal handler
Chase Douglas
chase.douglas at canonical.com
Mon Apr 9 11:17:37 PDT 2012
While we probably don't need to be signal safe here since we will never
return to the normal context, the logging signal context check will
cause unsafe logging to be unhandled. Using signal safe logging here
resolves the issue.
Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
os/osinit.c | 42 ++++++++++++++++++++++++++++++++++++------
1 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/os/osinit.c b/os/osinit.c
index e2a2208..c5c031e 100644
--- a/os/osinit.c
+++ b/os/osinit.c
@@ -109,11 +109,15 @@ OsSigHandler(int signo, siginfo_t * sip, void *unused)
OsSigHandler(int signo)
#endif
{
+ char string[20];
+
#ifdef RTLD_DI_SETSIGNAL
const char *dlerr = dlerror();
if (dlerr) {
- LogMessage(X_ERROR, "Dynamic loader error: %s\n", dlerr);
+ LogMessageVerbSigSafe(X_ERROR, 1, "Dynamic loader error: ");
+ LogMessageVerbSigSafe(X_NONE, 1, dlerr);
+ LogMessageVerbSigSafe(X_NONE, 1, "\n");
}
#endif /* RTLD_DI_SETSIGNAL */
@@ -129,22 +133,48 @@ OsSigHandler(int signo)
#ifdef SA_SIGINFO
if (sip->si_code == SI_USER) {
- ErrorF("Recieved signal %d sent by process %ld, uid %ld\n",
- signo, (long) sip->si_pid, (long) sip->si_uid);
+ LogMessageVerbSigSafe(X_NONE, -1, "Received signal ");
+ FormatUInt64(signo, string);
+ LogMessageVerbSigSafe(X_NONE, -1, string);
+ LogMessageVerbSigSafe(X_NONE, -1, " sent by process ");
+ FormatUInt64(sip->si_pid, string);
+ LogMessageVerbSigSafe(X_NONE, -1, string);
+ LogMessageVerbSigSafe(X_NONE, -1, ", uid ");
+ FormatUInt64(sip->si_uid, string);
+ LogMessageVerbSigSafe(X_NONE, -1, string);
+ LogMessageVerbSigSafe(X_NONE, -1, "\n");
}
else {
switch (signo) {
case SIGSEGV:
+ LogMessageVerbSigSafe(X_NONE, -1, "SIGSEGV ");
+ break;
case SIGBUS:
+ LogMessageVerbSigSafe(X_NONE, -1, "SIGBUS ");
+ break;
case SIGILL:
+ LogMessageVerbSigSafe(X_NONE, -1, "SIGILL ");
+ break;
case SIGFPE:
- ErrorF("%s at address %p\n", strsignal(signo), sip->si_addr);
+ LogMessageVerbSigSafe(X_NONE, -1, "SIGFPE ");
+ break;
+ }
+
+ if (signo == SIGSEGV || signo == SIGBUS || signo == SIGILL ||
+ signo == SIGFPE) {
+ LogMessageVerbSigSafe(X_NONE, -1, "at address 0x");
+ FormatUInt64Hex((unsigned long)sip->si_addr, string);
+ LogMessageVerbSigSafe(X_NONE, -1, string);
+ LogMessageVerbSigSafe(X_NONE, -1, "\n");
}
}
#endif
- FatalError("Caught signal %d (%s). Server aborting\n",
- signo, strsignal(signo));
+ LogMessageVerbSigSafe(X_NONE, -1, "Caught signal ");
+ FormatUInt64(signo, string);
+ LogMessageVerbSigSafe(X_NONE, -1, string);
+ LogMessageVerbSigSafe(X_NONE, -1, ". Server aborting\n");
+ exit(1);
}
void
--
1.7.9.1
More information about the xorg-devel
mailing list