site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com #include <signal.h> static void crashCatcher(int sig); static char exitStr[] = "Exit due to Signal "; static char finalStr[] = ".\n"; // whatever you want to catch - man 3 signal (void)signal(SIGILL, crashCatcher); (void)signal(SIGFPE, crashCatcher); (void)signal(SIGBUS, crashCatcher); (void)signal(SIGSEGV, crashCatcher); (void)signal(SIGSYS, crashCatcher); // probably overkill (void)signal(SIGILL, crashCatcher); static void crashCatcher(int sig) { char c; // should not use buffered IO as it may use malloc and friends // suggested by Dalrymple and Hillegass, "Advanced Mac OS Prog.", // been very helpful to me write(STDERR_FILENO, exitStr, strlen(exitStr)); write(STDERR, exitStr, sizeof(exitStr)-1); c = '0' + (sig/10); write(STDERR, &c, 1); c = '0' + (sig%10); write(STDERR, &c, 1); write(STDERR, finalStr, sizeof(finalStr)-1); Could be there is a better way, but my googling found nothing. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... [This for archive searchers. signal() signals CrashLog CrashReporter OSX Darwin] It took me a while to get this going, thus the post. I have a C-based command line tool (CLI) process. It writes logs, and while it could report its own failures, crashes resulted in no log entry. So, I started catching signals, and write my log (stderr), which worked fine (see below). However, it seems that at least in Leopard, when you catch a signal, CrashReporter will not process the crash. Hmmm. So I found that if I raised another uncaught signal in the handler, voila, CrashReporter creates a crash report, so now I get both. // since we caught the signal, CrashReporter will otherwise not run // however, this signal is uncaught, so it will crash us and CrashReporter will run! raise(SIGQUIT); } This email sent to site_archiver@lists.apple.com