Second try at landing bug 171343 - nsProfileAccess's signal handler should use SA_SIGINFO and sa_sigaction where available. r=ccarlen, cls, sr=brendan, a=chofmann.

git-svn-id: svn://10.0.0.236/trunk@131795 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bryner%netscape.com 2002-10-11 08:44:02 +00:00
parent 976ae209b8
commit 97d98b9475
3 changed files with 74 additions and 7 deletions

View File

@ -1381,6 +1381,19 @@ AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_STRUCT_ST_BLKSIZE
AC_MSG_CHECKING(for siginfo_t)
AC_CACHE_VAL(ac_cv_siginfo_t,
[AC_TRY_COMPILE([#define _POSIX_C_SOURCE 199506L
#include <signal.h>],
[siginfo_t* info;],
[ac_cv_siginfo_t=true],
[ac_cv_siginfo_t=false])])
if test "$ac_cv_siginfo_t" = true ; then
AC_DEFINE(HAVE_SIGINFO_T)
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
dnl Visual Age for os/2 also defines size_t and off_t in certain
dnl header files. These defines make Visual Age use the mozilla

View File

@ -1625,7 +1625,17 @@ static struct sigaction SIGABRT_oldact;
static struct sigaction SIGSEGV_oldact;
static struct sigaction SIGTERM_oldact;
#ifdef HAVE_SIGINFO_T
// There is no standard type definition for the type of sa_sigaction.
extern "C" {
typedef void (*my_sigaction_t)(int, siginfo_t*, void*);
}
void nsProfileLock::FatalSignalHandler(int signo, siginfo_t* info,
void* context)
#else
void nsProfileLock::FatalSignalHandler(int signo)
#endif
{
// Remove any locks still held.
RemovePidLockFiles();
@ -1660,12 +1670,25 @@ 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) {
#ifdef HAVE_SIGINFO_T
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
#endif
{
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,19 +1952,41 @@ 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;
#ifdef HAVE_SIGINFO_T
act.sa_sigaction = FatalSignalHandler;
act.sa_flags = SA_SIGINFO;
#else
act.sa_handler = FatalSignalHandler;
act.sa_flags = 0;
#endif
sigfillset(&act.sa_mask);
#ifdef HAVE_SIGINFO_T
#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); \
} \
PR_END_MACRO
#else
#define CATCH_SIGNAL(signame) \
PR_BEGIN_MACRO \
if (sigaction(signame, NULL, &oldact) == 0 && \
(oldact.sa_handler != SIG_IGN)) \
{ \
sigaction(signame, &act, &signame##_oldact); \
} \
PR_END_MACRO
#endif
CATCH_SIGNAL(SIGHUP);
CATCH_SIGNAL(SIGINT);
CATCH_SIGNAL(SIGQUIT);

View File

@ -33,6 +33,10 @@
#include <windows.h>
#endif
#ifdef XP_UNIX
#include <signal.h>
#endif
class ProfileStruct
{
public:
@ -198,7 +202,12 @@ private:
LHANDLE mLockFileHandle;
#elif defined (XP_UNIX)
static void RemovePidLockFiles();
#ifdef HAVE_SIGINFO_T
static void FatalSignalHandler(int signo, siginfo_t* info,
void* context);
#else
static void FatalSignalHandler(int signo);
#endif
static PRCList mPidLockList;
char* mPidLockFileName;
int mLockFileDesc;