1999-11-19 04:55:19 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ramiro
|
|
|
|
* Jerry.Kirk@Nexwarecorp.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This module is supposed to abstract signal handling away from the other
|
|
|
|
* platforms that do not support it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <signal.h>
|
1999-12-07 16:12:26 +03:00
|
|
|
#include <stdio.h>
|
1999-11-19 04:55:19 +03:00
|
|
|
#include "prthread.h"
|
1999-11-20 13:05:44 +03:00
|
|
|
#include "plstr.h"
|
2000-05-17 08:06:08 +04:00
|
|
|
#include "prenv.h"
|
|
|
|
|
|
|
|
#if defined(LINUX)
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <unistd.h>
|
2000-08-01 10:09:14 +04:00
|
|
|
#include <stdlib.h> // atoi
|
2000-05-17 08:06:08 +04:00
|
|
|
#endif
|
1999-11-19 04:55:19 +03:00
|
|
|
|
2000-08-22 07:42:32 +04:00
|
|
|
#if defined(SOLARIS)
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
1999-11-20 13:53:34 +03:00
|
|
|
#ifdef XP_BEOS
|
2001-07-28 02:16:33 +04:00
|
|
|
#include <be/app/Application.h>
|
1999-11-20 13:53:34 +03:00
|
|
|
#include <string.h>
|
|
|
|
extern "C" const char * strsignal(int);
|
|
|
|
#else
|
1999-11-19 04:55:19 +03:00
|
|
|
extern "C" char * strsignal(int);
|
1999-11-20 13:53:34 +03:00
|
|
|
#endif
|
|
|
|
|
1999-12-07 16:12:26 +03:00
|
|
|
#ifdef NTO
|
|
|
|
#include <photon/PhProto.h>
|
|
|
|
#include <sys/mman.h> /* for munlockall() */
|
|
|
|
#endif
|
|
|
|
|
1999-11-19 04:55:19 +03:00
|
|
|
static char _progname[1024] = "huh?";
|
|
|
|
|
1999-11-22 08:03:48 +03:00
|
|
|
//#ifdef DEBUG_ramiro
|
|
|
|
#if 0
|
1999-11-19 04:55:19 +03:00
|
|
|
#define CRAWL_STACK_ON_SIGSEGV
|
|
|
|
#endif // DEBUG_ramiro
|
|
|
|
|
|
|
|
#ifdef NTO
|
|
|
|
void abnormal_exit_handler(int signum)
|
|
|
|
{
|
|
|
|
/* Free any shared memory that has been allocated */
|
|
|
|
PgShmemCleanup();
|
|
|
|
|
1999-12-07 16:12:26 +03:00
|
|
|
#if defined(DEBUG)
|
1999-11-19 04:55:19 +03:00
|
|
|
if ( (signum == SIGSEGV)
|
|
|
|
|| (signum == SIGILL)
|
|
|
|
|| (signum == SIGABRT)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
PR_CurrentThread();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("prog = %s\npid = %d\nsignal = %s\n",
|
|
|
|
_progname, getpid(), strsignal(signum));
|
1999-11-19 04:55:19 +03:00
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Sleeping for 5 minutes.\n");
|
|
|
|
printf("Type 'gdb %s %d' to attatch your debugger to this thread.\n",
|
|
|
|
_progname, getpid());
|
1999-11-19 04:55:19 +03:00
|
|
|
|
|
|
|
sleep(300);
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Done sleeping...\n");
|
1999-11-19 04:55:19 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
#elif defined(CRAWL_STACK_ON_SIGSEGV)
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "nsTraceRefcnt.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
ah_crap_handler(int signum)
|
|
|
|
{
|
|
|
|
PR_CurrentThread();
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("prog = %s\npid = %d\nsignal = %s\n",
|
1999-11-19 04:55:19 +03:00
|
|
|
_progname,
|
|
|
|
getpid(),
|
|
|
|
strsignal(signum));
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("stack logged to someplace\n");
|
1999-11-19 04:55:19 +03:00
|
|
|
nsTraceRefcnt::WalkTheStack(stdout);
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Sleeping for 5 minutes.\n");
|
|
|
|
printf("Type 'gdb %s %d' to attatch your debugger to this thread.\n",
|
1999-11-19 04:55:19 +03:00
|
|
|
_progname,
|
|
|
|
getpid());
|
|
|
|
|
|
|
|
sleep(300);
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Done sleeping...\n");
|
1999-11-19 04:55:19 +03:00
|
|
|
}
|
|
|
|
#endif // CRAWL_STACK_ON_SIGSEGV
|
|
|
|
|
2001-07-28 02:16:33 +04:00
|
|
|
#ifdef XP_BEOS
|
|
|
|
void beos_signal_handler(int signum) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "beos_signal_handler: %d\n", signum);
|
|
|
|
#endif
|
|
|
|
if (be_app->Lock()) {
|
|
|
|
be_app->Quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1999-11-19 04:55:19 +03:00
|
|
|
|
|
|
|
void InstallUnixSignalHandlers(const char *ProgramName)
|
|
|
|
{
|
|
|
|
|
1999-11-20 13:05:44 +03:00
|
|
|
PL_strncpy(_progname,ProgramName, (sizeof(_progname)-1) );
|
1999-11-19 04:55:19 +03:00
|
|
|
|
|
|
|
#if defined(NTO)
|
|
|
|
/* Neutrino need this to free shared memory in case of a crash */
|
|
|
|
signal(SIGTERM, abnormal_exit_handler);
|
|
|
|
signal(SIGQUIT, abnormal_exit_handler);
|
|
|
|
signal(SIGINT, abnormal_exit_handler);
|
|
|
|
signal(SIGHUP, abnormal_exit_handler);
|
|
|
|
signal(SIGSEGV, abnormal_exit_handler);
|
|
|
|
signal(SIGILL, abnormal_exit_handler);
|
|
|
|
signal(SIGABRT, abnormal_exit_handler);
|
1999-12-07 16:12:26 +03:00
|
|
|
|
|
|
|
/* Tell the OS it can page any part of this program to virtual memory */
|
|
|
|
munlockall();
|
1999-11-19 04:55:19 +03:00
|
|
|
#elif defined(CRAWL_STACK_ON_SIGSEGV)
|
|
|
|
signal(SIGSEGV, ah_crap_handler);
|
|
|
|
signal(SIGILL, ah_crap_handler);
|
|
|
|
signal(SIGABRT, ah_crap_handler);
|
|
|
|
#endif // CRAWL_STACK_ON_SIGSEGV
|
2000-05-17 08:06:08 +04:00
|
|
|
|
|
|
|
#if defined(DEBUG) && defined(LINUX)
|
2000-08-01 05:46:52 +04:00
|
|
|
char *text = PR_GetEnv("MOZ_MEM_LIMIT");
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
long m = atoi(text);
|
2000-08-01 06:51:22 +04:00
|
|
|
m *= (1024*1024);
|
2000-05-17 08:06:08 +04:00
|
|
|
struct rlimit r;
|
|
|
|
r.rlim_cur = m;
|
|
|
|
r.rlim_max = m;
|
2000-05-17 10:59:50 +04:00
|
|
|
setrlimit(RLIMIT_AS, &r);
|
2000-05-17 08:06:08 +04:00
|
|
|
}
|
|
|
|
#endif
|
2000-08-22 07:42:32 +04:00
|
|
|
|
|
|
|
#if defined(SOLARIS)
|
|
|
|
|
|
|
|
#define NOFILES 512
|
|
|
|
|
|
|
|
// Boost Solaris file descriptors
|
|
|
|
{
|
|
|
|
struct rlimit rl;
|
|
|
|
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
|
|
|
|
|
|
|
|
if (rl.rlim_cur < NOFILES) {
|
|
|
|
rl.rlim_cur = NOFILES;
|
|
|
|
|
|
|
|
if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
|
|
|
|
perror("setrlimit(RLIMIT_NOFILE)");
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stderr, "Cannot exceed hard limit for open files");
|
2000-08-22 07:42:32 +04:00
|
|
|
}
|
|
|
|
#if defined(DEBUG)
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("File descriptors set to %d\n", rl.rlim_cur);
|
2000-08-22 07:42:32 +04:00
|
|
|
#endif //DEBUG
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //SOLARIS
|
2001-07-28 02:16:33 +04:00
|
|
|
|
|
|
|
#ifdef XP_BEOS
|
|
|
|
signal(SIGTERM, beos_signal_handler);
|
|
|
|
#endif
|
1999-11-20 13:05:44 +03:00
|
|
|
}
|