2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
|
|
|
//
|
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2004-11-15 01:58:30 +00:00
|
|
|
// Stuff related to stderr/stdout direction and exception handling;
|
|
|
|
// used by both core client and by apps
|
|
|
|
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
2005-12-02 22:29:35 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
#ifndef _WIN32
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <cstdlib>
|
2004-03-25 22:24:33 +00:00
|
|
|
#include "config.h"
|
2004-03-24 07:39:24 +00:00
|
|
|
#endif
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2006-04-19 18:06:26 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN32__)
|
2005-07-09 05:23:40 +00:00
|
|
|
#include "stackwalker_win.h"
|
|
|
|
#endif
|
|
|
|
|
2005-09-20 00:45:00 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include "mac_backtrace.h"
|
|
|
|
#endif
|
|
|
|
|
2004-11-17 00:01:58 +00:00
|
|
|
#ifdef __GLIBC__
|
|
|
|
#include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2006-04-10 06:20:02 +00:00
|
|
|
|
|
|
|
#include "app_ipc.h"
|
2004-03-24 20:53:43 +00:00
|
|
|
#include "error_numbers.h"
|
2004-03-24 07:39:24 +00:00
|
|
|
#include "filesys.h"
|
2004-02-29 00:50:05 +00:00
|
|
|
#include "util.h"
|
2006-04-10 06:20:02 +00:00
|
|
|
#include "parse.h"
|
|
|
|
#include "diagnostics.h"
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
|
|
|
|
#define MAX_STDERR_FILE_SIZE 2048*1024
|
|
|
|
#define MAX_STDOUT_FILE_SIZE 2048*1024
|
|
|
|
|
|
|
|
|
2006-04-10 06:20:02 +00:00
|
|
|
static int flags;
|
|
|
|
static char stdout_log[256];
|
|
|
|
static char stdout_archive[256];
|
|
|
|
static FILE* stdout_file;
|
|
|
|
static char stderr_log[256];
|
|
|
|
static char stderr_archive[256];
|
|
|
|
static FILE* stderr_file;
|
|
|
|
static char boinc_dir[256];
|
2006-04-15 22:45:02 +00:00
|
|
|
static int boinc_proxy_enabled;
|
|
|
|
static char boinc_proxy[256];
|
2006-04-10 06:20:02 +00:00
|
|
|
static char symstore[256];
|
2005-02-01 00:54:06 +00:00
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
#ifdef _WIN32
|
2006-03-22 04:46:21 +00:00
|
|
|
static int aborted_via_gui;
|
2005-02-01 00:54:06 +00:00
|
|
|
|
2006-03-21 19:04:05 +00:00
|
|
|
// This structure is used to keep track of stuff nessassary
|
|
|
|
// to dump backtraces for all threads during an abort or
|
|
|
|
// crash. This is platform specific in nature since it
|
|
|
|
// depends on the OS datatypes.
|
|
|
|
typedef struct _BOINC_THREADLIST {
|
|
|
|
char name[256];
|
|
|
|
DWORD thread_id;
|
|
|
|
HANDLE thread_handle;
|
|
|
|
} BOINC_THREADLIST, *PBOINC_THREADLIST;
|
|
|
|
|
2006-03-21 12:04:14 +00:00
|
|
|
static BOINC_THREADLIST diagnostics_threads[BOINC_THREADTYPE_COUNT];
|
|
|
|
|
2004-03-25 22:24:33 +00:00
|
|
|
LONG CALLBACK boinc_catch_signal(EXCEPTION_POINTERS *ExceptionInfo);
|
2006-04-13 22:17:23 +00:00
|
|
|
int __cdecl boinc_message_reporting(int reportType, char *szMsg, int *retVal);
|
2005-02-01 00:54:06 +00:00
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
#else
|
2005-02-01 00:54:06 +00:00
|
|
|
|
2004-03-25 22:24:33 +00:00
|
|
|
static void boinc_catch_signal(int signal);
|
2005-02-01 00:54:06 +00:00
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
// stub function for initializing the diagnostics environment.
|
2004-02-29 00:50:05 +00:00
|
|
|
//
|
2004-03-25 22:24:33 +00:00
|
|
|
int boinc_init_diagnostics(int _flags) {
|
2006-04-10 06:20:02 +00:00
|
|
|
int modified_flags = BOINC_DIAG_BOINCAPPLICATION | _flags;
|
2006-04-13 22:17:23 +00:00
|
|
|
return diagnostics_init(modified_flags, BOINC_DIAG_STDOUT, BOINC_DIAG_STDERR);
|
2005-02-01 00:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Used to cleanup the diagnostics environment.
|
|
|
|
//
|
|
|
|
int boinc_finish_diag() {
|
2005-04-09 02:21:11 +00:00
|
|
|
return BOINC_SUCCESS;
|
2005-02-01 00:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// to setup an unhandled exception filter on Windows
|
|
|
|
//
|
|
|
|
int boinc_install_signal_handlers() {
|
|
|
|
#ifdef _WIN32
|
2006-04-13 22:17:23 +00:00
|
|
|
SetUnhandledExceptionFilter(boinc_catch_signal);
|
2005-02-01 00:54:06 +00:00
|
|
|
#else //_WIN32
|
|
|
|
|
|
|
|
// register handlers for fatal internal signals
|
|
|
|
// so that they get reported in stderr.txt
|
|
|
|
// Do NOT catch SIGQUIT because core client uses that to kill app
|
|
|
|
//
|
|
|
|
boinc_set_signal_handler(SIGILL, boinc_catch_signal);
|
|
|
|
boinc_set_signal_handler(SIGABRT, boinc_catch_signal);
|
|
|
|
boinc_set_signal_handler(SIGBUS, boinc_catch_signal);
|
|
|
|
boinc_set_signal_handler(SIGSEGV, boinc_catch_signal);
|
|
|
|
boinc_set_signal_handler(SIGSYS, boinc_catch_signal);
|
|
|
|
boinc_set_signal_handler(SIGPIPE, boinc_catch_signal);
|
|
|
|
#endif //_WIN32
|
2005-04-09 02:21:11 +00:00
|
|
|
return 0;
|
2005-02-01 00:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// initialize the diagnostics environment.
|
|
|
|
//
|
2005-02-16 23:17:43 +00:00
|
|
|
int diagnostics_init(
|
|
|
|
int _flags, const char* stdout_prefix, const char* stderr_prefix
|
|
|
|
) {
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2004-03-25 22:24:33 +00:00
|
|
|
flags = _flags;
|
2005-02-01 00:54:06 +00:00
|
|
|
snprintf(stdout_log, sizeof(stdout_log), "%s.txt", stdout_prefix);
|
|
|
|
snprintf(stdout_archive, sizeof(stdout_archive), "%s.old", stdout_prefix);
|
|
|
|
snprintf(stderr_log, sizeof(stderr_log), "%s.txt", stderr_prefix);
|
|
|
|
snprintf(stderr_archive, sizeof(stderr_archive), "%s.old", stderr_prefix);
|
2006-04-10 06:20:02 +00:00
|
|
|
strcpy(boinc_dir, "");
|
2006-04-15 22:45:02 +00:00
|
|
|
boinc_proxy_enabled = 0;
|
|
|
|
strcpy(boinc_proxy, "");
|
2006-04-10 06:20:02 +00:00
|
|
|
strcpy(symstore, "");
|
2005-02-01 00:54:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Check for invalid parameter combinations
|
2006-04-13 22:17:23 +00:00
|
|
|
if ((flags & BOINC_DIAG_REDIRECTSTDERR) && (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE)) {
|
2005-02-01 00:54:06 +00:00
|
|
|
return ERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if ((flags & BOINC_DIAG_REDIRECTSTDOUT) && (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE)) {
|
2005-02-01 00:54:06 +00:00
|
|
|
return ERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
|
|
|
|
// Archive any old stderr.txt and stdout.txt files, if requested
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_ARCHIVESTDERR) {
|
2005-02-01 00:54:06 +00:00
|
|
|
boinc_copy(stderr_log, stderr_archive);
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_ARCHIVESTDOUT) {
|
|
|
|
boinc_copy(stdout_log, stdout_archive);
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
// Redirect stderr and/or stdout, if requested
|
|
|
|
//
|
|
|
|
if (flags & BOINC_DIAG_REDIRECTSTDERR) {
|
2005-02-01 00:54:06 +00:00
|
|
|
stderr_file = freopen(stderr_log, "a", stderr);
|
2006-04-13 22:17:23 +00:00
|
|
|
if (!stderr_file) {
|
2004-12-04 01:49:50 +00:00
|
|
|
return ERR_FOPEN;
|
2004-03-25 22:24:33 +00:00
|
|
|
}
|
2006-04-13 22:17:23 +00:00
|
|
|
setbuf(stderr_file, 0);
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE) {
|
2005-02-01 00:54:06 +00:00
|
|
|
stderr_file = freopen(stderr_log, "w", stderr);
|
2006-04-13 22:17:23 +00:00
|
|
|
if (NULL == stderr_file) {
|
2004-12-04 01:49:50 +00:00
|
|
|
return ERR_FOPEN;
|
2004-03-25 22:24:33 +00:00
|
|
|
}
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_REDIRECTSTDOUT) {
|
2005-04-09 02:21:11 +00:00
|
|
|
stdout_file = freopen(stdout_log, "a", stdout);
|
2006-04-13 22:17:23 +00:00
|
|
|
if (NULL == stdout_file) {
|
2004-12-04 01:49:50 +00:00
|
|
|
return ERR_FOPEN;
|
2004-03-25 22:24:33 +00:00
|
|
|
}
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE) {
|
2005-04-09 02:21:11 +00:00
|
|
|
stdout_file = freopen(stdout_log, "w", stdout);
|
2006-04-13 22:17:23 +00:00
|
|
|
if (NULL == stdout_file) {
|
2004-12-04 01:49:50 +00:00
|
|
|
return ERR_FOPEN;
|
|
|
|
}
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-21 12:04:14 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
|
|
|
// Initialize the thread list structure
|
|
|
|
// The data for this structure should be set by
|
|
|
|
// boinc_init or boinc_init_graphics.
|
|
|
|
int i;
|
|
|
|
for (i=0; i < BOINC_THREADTYPE_COUNT; i++) {
|
|
|
|
diagnostics_threads[i].thread_id = NULL;
|
|
|
|
diagnostics_threads[i].thread_handle = NULL;
|
|
|
|
}
|
|
|
|
strcpy(diagnostics_threads[BOINC_THREADTYPE_TIMER].name, "Timer");
|
|
|
|
strcpy(diagnostics_threads[BOINC_THREADTYPE_WORKER].name, "Worker");
|
|
|
|
strcpy(diagnostics_threads[BOINC_THREADTYPE_GRAPHICS].name, "Graphics");
|
|
|
|
|
|
|
|
#if defined(_DEBUG)
|
2004-03-24 07:39:24 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
_CrtSetReportHook(boinc_message_reporting);
|
2004-03-24 07:39:24 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED)
|
|
|
|
SET_CRT_DEBUG_FIELD(_CRTDBG_LEAK_CHECK_DF);
|
2004-03-24 07:39:24 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_HEAPCHECKENABLED)
|
|
|
|
if (flags & BOINC_DIAG_HEAPCHECKEVERYALLOC)
|
|
|
|
SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_ALWAYS_DF);
|
2005-02-27 08:28:52 +00:00
|
|
|
else
|
2006-04-13 22:17:23 +00:00
|
|
|
SET_CRT_DEBUG_FIELD(_CRTDBG_CHECK_EVERY_1024_DF);
|
2004-03-24 07:39:24 +00:00
|
|
|
|
2006-03-21 12:04:14 +00:00
|
|
|
#endif // defined(_DEBUG)
|
|
|
|
#endif // defined(_WIN32)
|
2004-03-24 07:39:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Install unhandled exception filters and signal traps.
|
2006-04-13 22:17:23 +00:00
|
|
|
if (BOINC_SUCCESS != boinc_install_signal_handlers()) {
|
2004-12-04 01:49:50 +00:00
|
|
|
return ERR_SIGNAL_OP;
|
|
|
|
}
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2006-04-10 06:20:02 +00:00
|
|
|
|
|
|
|
// Store the location of the BOINC directory for future use
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_BOINCAPPLICATION) {
|
2006-04-10 06:20:02 +00:00
|
|
|
char buf[256];
|
2006-04-15 22:45:02 +00:00
|
|
|
char proxy_address[256];
|
|
|
|
int proxy_port;
|
2006-04-10 06:20:02 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
FILE* p;
|
|
|
|
|
2006-04-15 22:45:02 +00:00
|
|
|
strcpy(buf, "");
|
|
|
|
strcpy(proxy_address, "");
|
|
|
|
proxy_port = 0;
|
|
|
|
|
2006-04-10 06:20:02 +00:00
|
|
|
p = fopen(INIT_DATA_FILE, "r");
|
|
|
|
if (!p) return ERR_FOPEN;
|
|
|
|
mf.init_file(p);
|
|
|
|
while(mf.fgets(buf, sizeof(buf))) {
|
|
|
|
if (match_tag(buf, "</app_init_data>")) break;
|
|
|
|
else if (parse_str(buf, "<boinc_dir>", boinc_dir, 256)) continue;
|
|
|
|
else if (parse_str(buf, "<project_symstore>", symstore, 256)) continue;
|
2006-04-17 22:41:29 +00:00
|
|
|
else if (match_tag(buf, "<use_http_proxy/>")) boinc_proxy_enabled = true;
|
2006-04-15 22:45:02 +00:00
|
|
|
else if (parse_str(buf, "<http_server_name>", proxy_address, 256)) continue;
|
|
|
|
else if (parse_int(buf, "<http_server_port>", proxy_port)) continue;
|
2006-04-10 06:20:02 +00:00
|
|
|
}
|
|
|
|
fclose(p);
|
2006-04-15 22:45:02 +00:00
|
|
|
|
2006-04-17 08:27:03 +00:00
|
|
|
if (boinc_proxy_enabled) {
|
|
|
|
int buffer_used = snprintf(boinc_proxy, sizeof(boinc_proxy), "%s:%d", proxy_address, proxy_port);
|
|
|
|
if ((sizeof(boinc_proxy) == buffer_used) || (-1 == buffer_used)) {
|
2006-04-15 22:45:02 +00:00
|
|
|
boinc_proxy[255] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2006-04-10 06:20:02 +00:00
|
|
|
}
|
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
return BOINC_SUCCESS;
|
2004-02-29 00:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
// Cycle the log files at regular events.
|
2004-02-29 00:50:05 +00:00
|
|
|
//
|
2005-02-01 00:54:06 +00:00
|
|
|
int diagnostics_cycle_logs() {
|
|
|
|
double f_size;
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
2004-05-31 18:13:01 +00:00
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
// If the stderr.txt or stdout.txt files are too big, cycle them
|
2004-05-31 18:13:01 +00:00
|
|
|
//
|
2005-02-01 00:54:06 +00:00
|
|
|
if (flags & BOINC_DIAG_REDIRECTSTDERR) {
|
2005-12-02 22:29:35 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
// OS/2 can't stat() open files!
|
|
|
|
struct stat sbuf;
|
|
|
|
fstat(fileno(stderr_file), &sbuf);
|
|
|
|
f_size = (double)sbuf.st_size;
|
|
|
|
#else
|
2005-02-01 00:54:06 +00:00
|
|
|
file_size(stderr_log, f_size);
|
2005-12-02 22:29:35 +00:00
|
|
|
#endif
|
2005-02-01 00:54:06 +00:00
|
|
|
if (MAX_STDERR_FILE_SIZE < f_size) {
|
2006-04-13 22:17:23 +00:00
|
|
|
fclose(stderr_file);
|
2005-02-01 00:54:06 +00:00
|
|
|
boinc_copy(stderr_log, stderr_archive);
|
2006-04-13 22:17:23 +00:00
|
|
|
stderr_file = freopen(stderr_log, "w", stderr);
|
|
|
|
if (NULL == stderr_file) return ERR_FOPEN;
|
2005-02-01 00:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & BOINC_DIAG_REDIRECTSTDOUT) {
|
2005-12-02 22:29:35 +00:00
|
|
|
#ifdef __EMX__
|
|
|
|
// OS/2 can't stat() open files!
|
|
|
|
struct stat sbuf;
|
|
|
|
fstat(fileno(stdout_file), &sbuf);
|
|
|
|
f_size = (double)sbuf.st_size;
|
|
|
|
#else
|
2005-02-01 00:54:06 +00:00
|
|
|
file_size(stdout_log, f_size);
|
2005-12-02 22:29:35 +00:00
|
|
|
#endif
|
2005-02-01 00:54:06 +00:00
|
|
|
if (MAX_STDOUT_FILE_SIZE < f_size) {
|
2006-04-13 22:17:23 +00:00
|
|
|
fclose(stdout_file);
|
|
|
|
boinc_copy(stdout_log, stdout_archive);
|
|
|
|
stdout_file = freopen(stdout_log, "w", stdout);
|
|
|
|
if (NULL == stdout_file) return ERR_FOPEN;
|
2005-02-01 00:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
return BOINC_SUCCESS;
|
2004-02-29 00:50:05 +00:00
|
|
|
}
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
2006-03-21 12:04:14 +00:00
|
|
|
int diagnostics_set_aborted_via_gui_flag() {
|
|
|
|
aborted_via_gui = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
int diagnostics_set_thread_info(int thread_type, DWORD thread_id, HANDLE thread_handle) {
|
2006-03-21 12:04:14 +00:00
|
|
|
diagnostics_threads[thread_type].thread_id = thread_id;
|
|
|
|
diagnostics_threads[thread_type].thread_handle = thread_handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
int diagnostics_is_thread_type_initialized(int thread_type) {
|
2006-03-21 12:04:14 +00:00
|
|
|
return (diagnostics_threads[thread_type].thread_id != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
// Used to unwind the stack and spew the callstack to stderr. Terminate the
|
|
|
|
// process afterwards and return the exception code as the exit code.
|
2004-02-29 00:50:05 +00:00
|
|
|
//
|
|
|
|
LONG CALLBACK boinc_catch_signal(EXCEPTION_POINTERS *pExPtrs) {
|
|
|
|
|
2004-08-31 02:47:20 +00:00
|
|
|
// Removed due to a nested exception problem
|
|
|
|
// RTW: 09/30/2004
|
|
|
|
/*
|
2005-04-09 02:21:11 +00:00
|
|
|
// Snagged from the latest stackwalker code base. This allows us to grab
|
|
|
|
// callstacks even in a stack overflow scenario
|
2006-04-13 22:17:23 +00:00
|
|
|
if (pExPtrs->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW)
|
2005-04-09 02:21:11 +00:00
|
|
|
{
|
|
|
|
static char MyStack[1024*128]; // be sure that we have enought space...
|
|
|
|
// it assumes that DS and SS are the same!!! (this is the case for Win32)
|
|
|
|
// change the stack only if the selectors are the same (this is the case for Win32)
|
|
|
|
//__asm push offset MyStack[1024*128];
|
|
|
|
//__asm pop esp;
|
|
|
|
__asm mov eax,offset MyStack[1024*128];
|
|
|
|
__asm mov esp,eax;
|
|
|
|
}
|
2004-08-31 02:47:20 +00:00
|
|
|
*/
|
2004-04-20 22:46:58 +00:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED)
|
|
|
|
CLEAR_CRT_DEBUG_FIELD(_CRTDBG_LEAK_CHECK_DF);
|
2004-04-20 22:46:58 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_HEAPCHECKENABLED)
|
|
|
|
CLEAR_CRT_DEBUG_FIELD(_CRTDBG_CHECK_EVERY_1024_DF);
|
2004-04-20 22:46:58 +00:00
|
|
|
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
|
|
|
|
2004-12-06 23:02:47 +00:00
|
|
|
PVOID exceptionAddr = pExPtrs->ExceptionRecord->ExceptionAddress;
|
2004-02-29 00:50:05 +00:00
|
|
|
DWORD exceptionCode = pExPtrs->ExceptionRecord->ExceptionCode;
|
|
|
|
|
2006-03-21 12:04:14 +00:00
|
|
|
char status[256];
|
|
|
|
char substatus[256];
|
|
|
|
int i;
|
2006-03-27 22:28:09 +00:00
|
|
|
bool bDumpedException;
|
2006-03-21 12:04:14 +00:00
|
|
|
CONTEXT c;
|
2004-07-13 13:54:09 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
static long lDetectNestedException = 0;
|
2004-02-29 00:50:05 +00:00
|
|
|
|
|
|
|
// If we've been in this procedure before, something went wrong so we immediately exit
|
2006-04-13 22:17:23 +00:00
|
|
|
if (InterlockedIncrement(&lDetectNestedException) > 1) {
|
|
|
|
TerminateProcess(GetCurrentProcess(), (UINT)ERR_NESTED_UNHANDLED_EXCEPTION_DETECTED);
|
2005-04-09 02:21:11 +00:00
|
|
|
}
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2006-04-08 20:22:08 +00:00
|
|
|
// Suspend the other threads.
|
|
|
|
for (i=0; i < BOINC_THREADTYPE_COUNT; i++) {
|
|
|
|
if ((GetCurrentThreadId() != diagnostics_threads[i].thread_id) && diagnostics_threads[i].thread_id) {
|
|
|
|
// Suspend the thread before getting the threads context, otherwise
|
|
|
|
// it'll be junk.
|
|
|
|
SuspendThread(diagnostics_threads[i].thread_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-19 18:06:26 +00:00
|
|
|
#if !defined(__CYGWIN__)
|
2006-04-08 20:22:08 +00:00
|
|
|
// Kickstart the debugger extensions
|
2006-04-15 22:45:02 +00:00
|
|
|
DebuggerInitialize(boinc_dir, symstore, boinc_proxy_enabled, boinc_proxy);
|
2006-04-08 20:22:08 +00:00
|
|
|
|
|
|
|
// Dump any useful information
|
|
|
|
DebuggerDisplayDiagnostics();
|
2006-04-12 23:07:17 +00:00
|
|
|
#endif
|
2006-04-08 20:22:08 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
switch (exceptionCode) {
|
2004-02-29 00:50:05 +00:00
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Access Violation");
|
|
|
|
if (pExPtrs->ExceptionRecord->NumberParameters == 2) {
|
|
|
|
switch(pExPtrs->ExceptionRecord->ExceptionInformation[0]) {
|
2005-04-09 02:21:11 +00:00
|
|
|
case 0: // read attempt
|
2006-04-13 22:17:23 +00:00
|
|
|
sprintf(substatus, "read attempt to address 0x%8.8X", pExPtrs->ExceptionRecord->ExceptionInformation[1]);
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
|
|
|
case 1: // write attempt
|
2006-04-13 22:17:23 +00:00
|
|
|
sprintf(substatus, "write attempt to address 0x%8.8X", pExPtrs->ExceptionRecord->ExceptionInformation[1]);
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_DATATYPE_MISALIGNMENT:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Data Type Misalignment");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_BREAKPOINT:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Breakpoint Encountered");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_SINGLE_STEP:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Single Instruction Executed");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Array Bounds Exceeded");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_FLT_DENORMAL_OPERAND:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Float Denormal Operand");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Divide by Zero");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_FLT_INEXACT_RESULT:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Float Inexact Result");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_FLT_INVALID_OPERATION:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Float Invalid Operation");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_FLT_OVERFLOW:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Float Overflow");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_FLT_STACK_CHECK:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Float Stack Check");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_FLT_UNDERFLOW:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Float Underflow");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Integer Divide by Zero");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_INT_OVERFLOW:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Integer Overflow");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_PRIV_INSTRUCTION:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Privileged Instruction");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_IN_PAGE_ERROR:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "In Page Error");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Illegal Instruction");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_NONCONTINUABLE_EXCEPTION:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Noncontinuable Exception");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_STACK_OVERFLOW:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Stack Overflow");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_INVALID_DISPOSITION:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Invalid Disposition");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_GUARD_PAGE:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Guard Page Violation");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case EXCEPTION_INVALID_HANDLE:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Invalid Handle");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
case CONTROL_C_EXIT:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Ctrl+C Exit");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-07-13 13:54:09 +00:00
|
|
|
default:
|
2006-04-13 22:17:23 +00:00
|
|
|
strcpy(status, "Unknown exception");
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-02-29 00:50:05 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "\n*** UNHANDLED EXCEPTION ****\n");
|
|
|
|
if (EXCEPTION_ACCESS_VIOLATION == exceptionCode) {
|
|
|
|
fprintf(stderr, "Reason: %s (0x%x) at address 0x%p %s\n\n", status, exceptionCode, exceptionAddr, substatus);
|
2005-04-09 02:21:11 +00:00
|
|
|
} else {
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "Reason: %s (0x%x) at address 0x%p\n\n", status, exceptionCode, exceptionAddr);
|
2005-04-09 02:21:11 +00:00
|
|
|
}
|
2006-04-13 22:17:23 +00:00
|
|
|
fflush(stderr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#if !defined(__MINGW32__) && !defined(__CYGWIN32__)
|
2005-04-09 02:21:11 +00:00
|
|
|
// Unwind the stack and spew it to stderr
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_DUMPCALLSTACKENABLED) {
|
2006-03-21 12:04:14 +00:00
|
|
|
// Dump the offending thread's stack first.
|
2006-03-27 22:28:09 +00:00
|
|
|
bDumpedException = false;
|
2006-03-21 12:04:14 +00:00
|
|
|
for (i=0; i < BOINC_THREADTYPE_COUNT; i++) {
|
|
|
|
if (GetCurrentThreadId() == diagnostics_threads[i].thread_id) {
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "*** Dump of the %s(offending) thread: ***\n", diagnostics_threads[i].name);
|
|
|
|
StackwalkFilter(pExPtrs, EXCEPTION_EXECUTE_HANDLER);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
2006-03-27 22:28:09 +00:00
|
|
|
bDumpedException = true;
|
2006-03-21 12:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-27 22:28:09 +00:00
|
|
|
if (!bDumpedException) {
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "*** Dump of the (offending) thread: ***\n");
|
|
|
|
StackwalkFilter(pExPtrs, EXCEPTION_EXECUTE_HANDLER);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
2006-03-27 22:28:09 +00:00
|
|
|
}
|
2006-03-21 12:04:14 +00:00
|
|
|
|
|
|
|
// Dump the other threads stack.
|
|
|
|
for (i=0; i < BOINC_THREADTYPE_COUNT; i++) {
|
|
|
|
if ((GetCurrentThreadId() != diagnostics_threads[i].thread_id) && diagnostics_threads[i].thread_id) {
|
|
|
|
// Get the thread context
|
|
|
|
memset(&c, 0, sizeof(CONTEXT));
|
|
|
|
c.ContextFlags = CONTEXT_FULL;
|
|
|
|
GetThreadContext(diagnostics_threads[i].thread_handle, &c);
|
|
|
|
|
|
|
|
// Dump the thread's stack.
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "*** Dump of the %s thread: ***\n", diagnostics_threads[i].name);
|
|
|
|
StackwalkThread(diagnostics_threads[i].thread_handle, &c);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
2006-03-21 12:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2005-12-01 00:25:21 +00:00
|
|
|
#endif
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "Exiting...\n");
|
|
|
|
fflush(stderr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
// Force terminate the app letting BOINC know an exception has occurred.
|
2006-03-21 12:04:14 +00:00
|
|
|
if (aborted_via_gui) {
|
2006-04-13 22:17:23 +00:00
|
|
|
TerminateProcess(GetCurrentProcess(), ERR_ABORTED_VIA_GUI);
|
2006-03-21 12:04:14 +00:00
|
|
|
} else {
|
2006-04-13 22:17:23 +00:00
|
|
|
TerminateProcess(GetCurrentProcess(), pExPtrs->ExceptionRecord->ExceptionCode);
|
2006-03-21 12:04:14 +00:00
|
|
|
}
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
// We won't make it to this point, but make the compiler happy anyway.
|
|
|
|
return 1;
|
2004-02-29 00:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
|
|
|
|
// Trap ASSERTs and TRACEs from the CRT and spew them to stderr.
|
2004-02-29 00:50:05 +00:00
|
|
|
//
|
2006-04-13 22:17:23 +00:00
|
|
|
int __cdecl boinc_message_reporting(int reportType, char *szMsg, int *retVal){
|
2005-04-09 02:21:11 +00:00
|
|
|
(*retVal) = 0;
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
switch(reportType){
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
case _CRT_WARN:
|
|
|
|
case _CRT_ERROR:
|
2004-03-24 07:39:24 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
OutputDebugString(szMsg); // Reports string to the debugger output window
|
2004-07-13 13:54:09 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_TRACETOSTDERR) {
|
|
|
|
fprintf(stderr, szMsg);
|
|
|
|
fflush(stderr);
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
2004-07-13 13:54:09 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_TRACETOSTDOUT) {
|
|
|
|
fprintf(stdout, szMsg);
|
|
|
|
fflush(stdout);
|
2004-03-24 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2005-04-09 02:21:11 +00:00
|
|
|
case _CRT_ASSERT:
|
2004-03-31 06:25:40 +00:00
|
|
|
|
|
|
|
OutputDebugString("ASSERT: "); // Reports string to the debugger output window
|
|
|
|
OutputDebugString(szMsg); // Reports string to the debugger output window
|
|
|
|
OutputDebugString("\n"); // Reports string to the debugger output window
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "ASSERT: %s\n", szMsg);
|
|
|
|
fflush(stderr);
|
2004-03-31 06:25:40 +00:00
|
|
|
|
|
|
|
(*retVal) = 1;
|
2005-04-09 02:21:11 +00:00
|
|
|
break;
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
}
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
return(TRUE);
|
2004-07-13 13:54:09 +00:00
|
|
|
}
|
2004-02-29 00:50:05 +00:00
|
|
|
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
// Converts the BOINCTRACE macro into a single string and report it
|
|
|
|
// to the CRT so it can be reported via the normal means.
|
2004-02-29 00:50:05 +00:00
|
|
|
//
|
2004-03-25 22:24:33 +00:00
|
|
|
void boinc_trace(const char *pszFormat, ...) {
|
2005-04-09 02:21:11 +00:00
|
|
|
static char szBuffer[4096];
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
// Trace messages should only be reported if running as a standalone
|
|
|
|
// application or told too.
|
|
|
|
if ((flags & BOINC_DIAG_TRACETOSTDERR) ||
|
2006-04-13 22:17:23 +00:00
|
|
|
(flags & BOINC_DIAG_TRACETOSTDOUT)) {
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
memset(szBuffer, 0, sizeof(szBuffer));
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_list ptr;
|
|
|
|
va_start(ptr, pszFormat);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_end(ptr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2006-04-13 08:37:25 +00:00
|
|
|
_CrtDbgReport(_CRT_WARN, NULL, NULL, NULL, "TRACE[%d]: %s", GetCurrentThreadId(), szBuffer);
|
2005-04-09 02:21:11 +00:00
|
|
|
}
|
2004-02-29 00:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
// Converts the BOINCINFO macro into a single string and report it
|
|
|
|
// to stderr so it can be reported via the normal means.
|
2004-02-29 00:50:05 +00:00
|
|
|
//
|
2005-03-16 20:29:43 +00:00
|
|
|
void boinc_info_debug(const char *pszFormat, ...){
|
2005-04-09 02:21:11 +00:00
|
|
|
static char szBuffer[4096];
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
memset(szBuffer, 0, sizeof(szBuffer));
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_list ptr;
|
|
|
|
va_start(ptr, pszFormat);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_end(ptr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
_CrtDbgReport(_CRT_WARN, NULL, NULL, NULL, "%s", szBuffer);
|
2004-02-29 00:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else // _DEBUG
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
|
|
|
|
// Converts the BOINCINFO macro into a single string and report it
|
|
|
|
// to stderr so it can be reported via the normal means.
|
2004-02-29 00:50:05 +00:00
|
|
|
//
|
2005-03-16 20:29:43 +00:00
|
|
|
void boinc_info_release(const char *pszFormat, ...){
|
2005-04-09 02:21:11 +00:00
|
|
|
static char szBuffer[4096];
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
memset(szBuffer, 0, sizeof(szBuffer));
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_list ptr;
|
|
|
|
va_start(ptr, pszFormat);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_end(ptr);
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "%s", szBuffer);
|
|
|
|
fflush(stderr);
|
2004-02-29 00:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
2005-03-16 20:29:43 +00:00
|
|
|
|
|
|
|
#else // _WIN32
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
// Converts the BOINCTRACE macro into a single string and report it
|
|
|
|
// to the CRT so it can be reported via the normal means.
|
|
|
|
//
|
|
|
|
void boinc_trace(const char *pszFormat, ...) {
|
2005-04-09 02:21:11 +00:00
|
|
|
static char szBuffer[4096];
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
// Trace messages should only be reported if running as a standalone
|
|
|
|
// application or told too.
|
|
|
|
if ((flags & BOINC_DIAG_TRACETOSTDERR) ||
|
2006-04-13 22:17:23 +00:00
|
|
|
(flags & BOINC_DIAG_TRACETOSTDOUT)) {
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
memset(szBuffer, 0, sizeof(szBuffer));
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_list ptr;
|
|
|
|
va_start(ptr, pszFormat);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-10-24 13:10:18 +00:00
|
|
|
vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_end(ptr);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_TRACETOSTDERR) {
|
|
|
|
fprintf(stderr, "TRACE: %s", szBuffer);
|
|
|
|
fflush(stderr);
|
2005-03-16 20:29:43 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
if (flags & BOINC_DIAG_TRACETOSTDOUT) {
|
|
|
|
fprintf(stdout, "TRACE: %s", szBuffer);
|
|
|
|
fflush(stdout);
|
2005-03-16 20:29:43 +00:00
|
|
|
}
|
2005-04-09 02:21:11 +00:00
|
|
|
}
|
2005-03-16 20:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Converts the BOINCINFO macro into a single string and report it
|
|
|
|
// to stderr so it can be reported via the normal means.
|
|
|
|
//
|
|
|
|
void boinc_info_debug(const char *pszFormat, ...){
|
2005-04-09 02:21:11 +00:00
|
|
|
static char szBuffer[4096];
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
memset(szBuffer, 0, sizeof(szBuffer));
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_list ptr;
|
|
|
|
va_start(ptr, pszFormat);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-10-24 13:10:18 +00:00
|
|
|
vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_end(ptr);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "%s", szBuffer);
|
|
|
|
fflush(stderr);
|
2005-03-16 20:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else // _DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
// Converts the BOINCINFO macro into a single string and report it
|
|
|
|
// to stderr so it can be reported via the normal means.
|
|
|
|
//
|
|
|
|
void boinc_info_release(const char *pszFormat, ...){
|
2005-04-09 02:21:11 +00:00
|
|
|
static char szBuffer[4096];
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
memset(szBuffer, 0, sizeof(szBuffer));
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_list ptr;
|
|
|
|
va_start(ptr, pszFormat);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2005-04-09 02:21:11 +00:00
|
|
|
va_end(ptr);
|
2005-03-16 20:29:43 +00:00
|
|
|
|
2006-04-13 22:17:23 +00:00
|
|
|
fprintf(stderr, "%s", szBuffer);
|
|
|
|
fflush(stderr);
|
2005-03-16 20:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
|
|
|
|
2004-02-29 00:50:05 +00:00
|
|
|
#endif // _WIN32
|
|
|
|
|
|
|
|
|
|
|
|
// Diagnostics for POSIX Compatible systems.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
|
|
2004-03-24 19:47:51 +00:00
|
|
|
|
|
|
|
// Set a signal handler only if it is not currently ignored
|
|
|
|
//
|
2004-03-25 22:24:33 +00:00
|
|
|
void boinc_set_signal_handler(int sig, void(*handler)(int)) {
|
2004-03-17 04:56:46 +00:00
|
|
|
#ifdef HAVE_SIGACTION
|
|
|
|
struct sigaction temp;
|
|
|
|
sigaction(sig, NULL, &temp);
|
|
|
|
if (temp.sa_handler != SIG_IGN) {
|
2004-03-24 19:47:51 +00:00
|
|
|
temp.sa_handler = handler;
|
2005-04-09 02:21:11 +00:00
|
|
|
// sigemptyset(&temp.sa_mask);
|
2004-03-24 07:39:24 +00:00
|
|
|
sigaction(sig, &temp, NULL);
|
2004-03-17 04:56:46 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void (*temp)(int);
|
|
|
|
temp = signal(sig, boinc_catch_signal);
|
|
|
|
if (temp == SIG_IGN) {
|
2004-03-24 07:39:24 +00:00
|
|
|
signal(sig, SIG_IGN);
|
2004-03-17 04:56:46 +00:00
|
|
|
}
|
2004-03-24 19:47:51 +00:00
|
|
|
#endif /* HAVE_SIGACTION */
|
2004-03-17 04:56:46 +00:00
|
|
|
}
|
2004-02-29 00:50:05 +00:00
|
|
|
|
2004-03-24 19:47:51 +00:00
|
|
|
|
|
|
|
// Set a signal handler even if it is currently ignored
|
|
|
|
//
|
2004-03-25 22:24:33 +00:00
|
|
|
void boinc_set_signal_handler_force(int sig, void(*handler)(int)) {
|
2004-03-24 19:47:51 +00:00
|
|
|
#ifdef HAVE_SIGACTION
|
|
|
|
struct sigaction temp;
|
|
|
|
sigaction(sig, NULL, &temp);
|
|
|
|
temp.sa_handler = handler;
|
2005-01-08 01:17:51 +00:00
|
|
|
// sigemptyset(&temp.sa_mask);
|
2004-03-24 19:47:51 +00:00
|
|
|
sigaction(sig, &temp, NULL);
|
|
|
|
#else
|
|
|
|
void (*temp)(int);
|
2004-03-25 18:59:43 +00:00
|
|
|
temp = signal(sig, boinc_catch_signal);
|
2004-03-24 19:47:51 +00:00
|
|
|
signal(sig, SIG_IGN);
|
|
|
|
#endif /* HAVE_SIGACTION */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-25 22:24:33 +00:00
|
|
|
void boinc_catch_signal(int signal) {
|
2004-02-29 00:50:05 +00:00
|
|
|
switch(signal) {
|
2004-10-22 05:46:25 +00:00
|
|
|
case SIGHUP: fprintf(stderr, "SIGHUP: terminal line hangup");
|
|
|
|
return;
|
2004-02-29 00:50:05 +00:00
|
|
|
case SIGINT: fprintf(stderr, "SIGINT: interrupt program"); break;
|
|
|
|
case SIGILL: fprintf(stderr, "SIGILL: illegal instruction"); break;
|
|
|
|
case SIGABRT: fprintf(stderr, "SIGABRT: abort called"); break;
|
|
|
|
case SIGBUS: fprintf(stderr, "SIGBUS: bus error"); break;
|
|
|
|
case SIGSEGV: fprintf(stderr, "SIGSEGV: segmentation violation"); break;
|
|
|
|
case SIGSYS: fprintf(stderr, "SIGSYS: system call given invalid argument"); break;
|
2004-10-22 05:46:25 +00:00
|
|
|
case SIGPIPE: fprintf(stderr, "SIGPIPE: write on a pipe with no reader");
|
|
|
|
return;
|
2004-02-29 00:50:05 +00:00
|
|
|
default: fprintf(stderr, "unknown signal %d", signal); break;
|
|
|
|
}
|
2004-11-15 01:58:30 +00:00
|
|
|
|
|
|
|
#ifdef __GLIBC__
|
|
|
|
void *array[64];
|
|
|
|
size_t size;
|
|
|
|
size = backtrace (array, 64);
|
2004-12-18 01:07:08 +00:00
|
|
|
fprintf(stderr, "Stack trace (%d frames):\n", size);
|
2004-11-15 01:58:30 +00:00
|
|
|
backtrace_symbols_fd(array, size, fileno(stderr));
|
|
|
|
#endif
|
|
|
|
|
2005-09-20 00:45:00 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
PrintBacktrace();
|
|
|
|
#endif
|
|
|
|
|
2004-02-29 00:50:05 +00:00
|
|
|
fprintf(stderr, "\nExiting...\n");
|
|
|
|
exit(ERR_SIGNAL_CATCH);
|
|
|
|
}
|
|
|
|
|
2004-03-24 19:47:51 +00:00
|
|
|
|
2004-02-29 00:50:05 +00:00
|
|
|
#endif
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_4967ad204c = "$Id$";
|