• 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
Re: Catching signal errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Catching signal errors


  • Subject: Re: Catching signal errors
  • From: Kevin Harris <email@hidden>
  • Date: Mon, 07 Feb 2005 12:50:31 -0700

Matt Watson wrote:

void fatalSigHandler(int sig, siginfo_t* info, void* context)
{
// We are very limited in what we are allowed to do in a signal handler. // Memory should not be allocated, and most libc functions should not be used.
static char sig_message[] = "Aborting: Fatal signal occurred!\n";


   write(1, sig_message, sizeof(sig_message));
   exit(1);
}


Never call exit() from a signal handler. You want _Exit() instead. exit() will call atexit() handlers which will are likely not signal-safe. And you probably want to use fd 2 (stderr), instead of fd 1 in the write() call.


Good suggestions. That's especially important when using dlopen or NSLinkModule on libraries. They could cause further signals or even signal deadlocks when they get unloaded.


That said: if you're not going to add any more info in your signal handler, or do any cleanup like unlink() files, it may just be best to let it crash and generate a crash log.


I assumed that he'd replace the handler with something else.

One of the handlers I have for a project calls execv() to restart the daemon in case of a crash. That is after writing errors to a log and closing open file handles/resetting signal masks (as they are both inherited by the new process), and doing some other general cleanup of the daemon's lock/state files.

-Kevin-
_______________________________________________
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


  • Follow-Ups:
    • Re: Catching signal errors
      • From: Rick Steele <email@hidden>
References: 
 >Catching signal errors (From: Rick Steele <email@hidden>)
 >Re: Catching signal errors (From: Kevin Harris <email@hidden>)
 >Re: Catching signal errors (From: Matt Watson <email@hidden>)

  • Prev by Date: Re: Catching signal errors
  • Next by Date: Re: detecting logout
  • Previous by thread: Re: Catching signal errors
  • Next by thread: Re: Catching signal errors
  • Index(es):
    • Date
    • Thread