diff --git a/profile/src/nsProfileAccess.cpp b/profile/src/nsProfileAccess.cpp index 97c1d3c41c7e..44b24a6159b4 100644 --- a/profile/src/nsProfileAccess.cpp +++ b/profile/src/nsProfileAccess.cpp @@ -1625,7 +1625,11 @@ static struct sigaction SIGABRT_oldact; static struct sigaction SIGSEGV_oldact; static struct sigaction SIGTERM_oldact; -void nsProfileLock::FatalSignalHandler(int signo) +// There is no standard type definition for the type of sa_sigaction. +typedef void (*my_sigaction_t)(int, siginfo_t*, void*); + +void nsProfileLock::FatalSignalHandler(int signo, siginfo_t* info, + void* context) { // Remove any locks still held. RemovePidLockFiles(); @@ -1660,12 +1664,22 @@ void nsProfileLock::FatalSignalHandler(int signo) break; } - if (oldact && - oldact->sa_handler && - oldact->sa_handler != SIG_DFL && - oldact->sa_handler != SIG_IGN) - { - oldact->sa_handler(signo); + if (oldact) { + if (oldact->sa_flags & SA_SIGINFO) { + if (oldact->sa_sigaction && + oldact->sa_sigaction != (my_sigaction_t) SIG_DFL && + oldact->sa_sigaction != (my_sigaction_t) SIG_IGN) + { + oldact->sa_sigaction(signo, info, context); + } + } else { + if (oldact->sa_handler && + oldact->sa_handler != SIG_DFL && + oldact->sa_handler != SIG_IGN) + { + oldact->sa_handler(signo); + } + } } // Backstop exit call, just in case. @@ -1929,14 +1943,16 @@ nsresult nsProfileLock::Lock(nsILocalFile* aFile) // Don't arm a handler if the signal is being ignored, e.g., // because mozilla is run via nohup. struct sigaction act, oldact; - act.sa_handler = FatalSignalHandler; - act.sa_flags = 0; + act.sa_sigaction = FatalSignalHandler; + act.sa_flags = SA_SIGINFO; sigfillset(&act.sa_mask); #define CATCH_SIGNAL(signame) \ PR_BEGIN_MACRO \ if (sigaction(signame, NULL, &oldact) == 0 && \ - oldact.sa_handler != SIG_IGN) \ + ((oldact.sa_flags & SA_SIGINFO) ? \ + (oldact.sa_sigaction != (my_sigaction_t) SIG_IGN) : \ + (oldact.sa_handler != SIG_IGN))) \ { \ sigaction(signame, &act, &signame##_oldact); \ } \ diff --git a/profile/src/nsProfileAccess.h b/profile/src/nsProfileAccess.h index a96e29f488bf..98f98c2da670 100644 --- a/profile/src/nsProfileAccess.h +++ b/profile/src/nsProfileAccess.h @@ -33,6 +33,10 @@ #include #endif +#ifdef XP_UNIX +#include +#endif + class ProfileStruct { public: @@ -198,7 +202,8 @@ private: LHANDLE mLockFileHandle; #elif defined (XP_UNIX) static void RemovePidLockFiles(); - static void FatalSignalHandler(int signo); + static void FatalSignalHandler(int signo, siginfo_t* info, + void* context); static PRCList mPidLockList; char* mPidLockFileName; int mLockFileDesc;