• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
HowTo: catch a signal and get a CrashLog too (Leopard)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HowTo: catch a signal and get a CrashLog too (Leopard)


  • Subject: HowTo: catch a signal and get a CrashLog too (Leopard)
  • From: David Hoerl <email@hidden>
  • Date: Tue, 18 Dec 2007 16:54:13 -0500

[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.

#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);
    write(STDERR, &c, 1);
    write(STDERR, finalStr, sizeof(finalStr)-1);

// 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);
}


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      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: How does 'Finder' open an application and bring the window to the front?
  • Next by Date: Closing an IOUserClient
  • Previous by thread: Re: How does 'Finder' open an application and bring the window to the front?
  • Next by thread: Re: HowTo: catch a signal and get a CrashLog too (Leopard)
  • Index(es):
    • Date
    • Thread