From e442d3ce7e10ad08b3fe225b66ff2fa1bc903856 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Tue, 1 Feb 2005 00:54:06 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=5261 --- checkin_notes | 33 +++++ client/client_state.C | 1 + client/client_state.h | 2 +- client/cs_cmdline.C | 5 +- client/cs_files.C | 20 --- client/file_names.h | 3 - client/main.C | 29 +++-- client/win/wingui_mainwindow.cpp | 5 - clientgui/BOINCGUIApp.cpp | 40 ++++-- clientgui/BOINCGUIApp.h | 4 +- clientgui/LogBOINC.cpp | 40 ++++++ clientgui/LogBOINC.h | 40 ++++++ clientgui/Makefile.am | 1 + clientgui/ViewMessages.cpp | 2 + clientgui/ViewProjects.cpp | 1 + clientgui/ViewResources.cpp | 1 + clientgui/ViewTransfers.cpp | 1 + clientgui/ViewWork.cpp | 1 + clientgui/stdwx.h | 3 + lib/diagnostics.C | 209 ++++++++++++++++++++----------- lib/diagnostics.h | 15 ++- win_build/BOINCGUI.vcproj | 30 +++++ 22 files changed, 356 insertions(+), 130 deletions(-) create mode 100644 clientgui/LogBOINC.cpp create mode 100644 clientgui/LogBOINC.h diff --git a/checkin_notes b/checkin_notes index 35ce048118..3c753f577c 100755 --- a/checkin_notes +++ b/checkin_notes @@ -23643,3 +23643,36 @@ David 31 Jan 2005 main.C,h win/ win_service.cpp + +Rom 31 Jan 2005 + - Implement log files for the BOINC Manager + - Implement call stacks, and memory leak detection for the BOINC Manager + on Windows + - Implement log rotation for both the core client and manager + - Implement stderr and stdout redirects with the core client + - Make the manager start the core client with IO redirection enabled + - Cleanup some more memory leaks in the BOINC Manager + - Enabled the STL use of the debug heap on Windows + + client/ + client_state.C, .h + cs_cmdline.C + cs_files.C + file_names.h + main.C + client/win/ + wingui_mainwindow.cpp + clientgui/ + BOINCGUI.cpp, .h + LogBOINC.cpp, .h (Added) + Makefile.am + ViewProjects.cpp + ViewMessages.cpp + ViewResources.cpp + ViewTransfers.cpp + ViewWork.cpp + stdwx.h + lib/ + diagnostics.C, .h + win_build/ + BOINCGUI.vcproj diff --git a/client/client_state.C b/client/client_state.C index 8b0bf21f46..8fb1deca2a 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -105,6 +105,7 @@ CLIENT_STATE::CLIENT_STATE() { pers_retry_delay_max = PERS_RETRY_DELAY_MAX; pers_giveup = PERS_GIVEUP; executing_as_daemon = false; + redirect_io = false; cpu_sched_last_time = 0; cpu_sched_work_done_this_period = 0; must_schedule_cpus = true; diff --git a/client/client_state.h b/client/client_state.h index 72447e3d15..399edab0e4 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -121,6 +121,7 @@ public: bool network_suspended; bool executing_as_daemon; bool size_overflow; + bool redirect_io; private: bool client_state_dirty; @@ -231,7 +232,6 @@ public: // --------------- cs_files.C: public: - void trunc_stderr_stdout(); bool start_new_file_xfer(PERS_FILE_XFER&); private: int make_project_dirs(); diff --git a/client/cs_cmdline.C b/client/cs_cmdline.C index 996106e8a5..07745892c8 100644 --- a/client/cs_cmdline.C +++ b/client/cs_cmdline.C @@ -44,7 +44,8 @@ static void print_options(char* prog) { " -update_prefs URL contact a project to update preferences\n" " -run_cpu_benchmarks run the CPU benchmarks\n" " -check_all_logins check input from remote users\n" - " -allow_remote_gui_rpc allow remote GUI RPC connections\n", + " -allow_remote_gui_rpc allow remote GUI RPC connections\n" + " -redirectio redirect stdout and stderr to log files\n", prog ); } @@ -67,6 +68,8 @@ void CLIENT_STATE::parse_cmdline(int argc, char** argv) { check_all_logins = true; } else if (ARG(daemon)) { executing_as_daemon = true; + } else if (ARG(redirectio)) { + redirect_io = true; } else if (ARG(return_results_immediately)) { return_results_immediately = true; } else if (ARG(skip_cpu_benchmarks)) { diff --git a/client/cs_files.C b/client/cs_files.C index 42316d4f2f..cd970fbc91 100644 --- a/client/cs_files.C +++ b/client/cs_files.C @@ -69,26 +69,6 @@ bool CLIENT_STATE::start_new_file_xfer(PERS_FILE_XFER& pfx) { return true; } -void CLIENT_STATE::trunc_stderr_stdout() { - double f_size; - - fflush(stdout); - fflush(stderr); - - // If the stderr.txt or stdout.txt files are too big, reset them - // TODO: should we tell the user we're resetting these? - // TODO: should rotate files, not truncate!! - // - file_size(STDERR_FILE_NAME, f_size); - if (f_size > MAX_STDERR_FILE_SIZE) { - freopen(STDERR_FILE_NAME, "w", stderr); - } - file_size(STDOUT_FILE_NAME, f_size); - if (f_size > MAX_STDOUT_FILE_SIZE) { - freopen(STDOUT_FILE_NAME, "w", stdout); - } -} - // Make a directory for each of the projects in the client state // int CLIENT_STATE::make_project_dirs() { diff --git a/client/file_names.h b/client/file_names.h index c4845d890f..deffb83631 100644 --- a/client/file_names.h +++ b/client/file_names.h @@ -43,9 +43,6 @@ extern int check_unique_instance(); extern void get_sched_request_filename(PROJECT&, char*); extern void get_sched_reply_filename(PROJECT&, char*); -#define MAX_STDERR_FILE_SIZE 1024*1024 -#define MAX_STDOUT_FILE_SIZE 1024*1024 - #define PROJECTS_DIR "projects" #define SLOTS_DIR "slots" #define STATE_FILE_NEXT "client_state_next.xml" diff --git a/client/main.C b/client/main.C index 4acbdd5854..9749c62bd6 100644 --- a/client/main.C +++ b/client/main.C @@ -83,6 +83,9 @@ void show_message(PROJECT *p, char* msg, int priority) { char event_message[2048]; #endif + // Cycle the log files if we need to + diagnostics_cycle_logs(); + strcpy(message, msg); while (strlen(message)&&message[strlen(message)-1] == '\n') { message[strlen(message)-1] = 0; @@ -233,14 +236,22 @@ void boinc_init(int argc, char** argv) { gstate.parse_env_vars(); - boinc_init_diagnostics( - BOINC_DIAG_DUMPCALLSTACKENABLED - | BOINC_DIAG_HEAPCHECKENABLED - | BOINC_DIAG_TRACETOSTDERR -#ifdef _WIN32 - //| BOINC_DIAG_REDIRECTSTDERR - //| BOINC_DIAG_REDIRECTSTDOUT -#endif + // Initialize the BOINC Diagnostics Framework + int dwDiagnosticsFlags = + BOINC_DIAG_DUMPCALLSTACKENABLED | + BOINC_DIAG_HEAPCHECKENABLED | + BOINC_DIAG_TRACETOSTDOUT; + + if (gstate.redirect_io || gstate.executing_as_daemon) { + dwDiagnosticsFlags |= + BOINC_DIAG_REDIRECTSTDERR | + BOINC_DIAG_REDIRECTSTDOUT; + } + + diagnostics_init( + dwDiagnosticsFlags, + "stdoutdae", + "stderrdae" ); retval = check_unique_instance(); @@ -376,7 +387,7 @@ int main(int argc, char** argv) { retval = boinc_main_loop(); } #else - boinc_main_loop(); + retval = boinc_main_loop(); #endif #ifdef _WIN32 diff --git a/client/win/wingui_mainwindow.cpp b/client/win/wingui_mainwindow.cpp index 801359679b..612af33560 100755 --- a/client/win/wingui_mainwindow.cpp +++ b/client/win/wingui_mainwindow.cpp @@ -2165,11 +2165,6 @@ void CMainWindow::OnTimer(UINT uEventID) { while(gstate.do_something(dtime())); NetCheck(); // check if network connection can be terminated - // TODO: check this after writing a message, not here!!! - if ((counter % 10) == 0) { - gstate.trunc_stderr_stdout(); - } - UpdateGUI(&gstate); // Start the timer again diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index aa8ffca76c..3b52686117 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -23,6 +23,7 @@ #include "stdwx.h" #include "BOINCGUIApp.h" +#include "diagnostics.h" #include "MainFrame.h" #include "MainDocument.h" @@ -53,9 +54,31 @@ bool CBOINCGUIApp::OnInit() m_hIdleDetectionDll = NULL; #endif - // Enable Trace Masks - //wxLog::AddTraceMask( wxT("Function Start/End") ); + // Initialize the BOINC Diagnostics Framework + int dwDiagnosticsFlags = + BOINC_DIAG_DUMPCALLSTACKENABLED | + BOINC_DIAG_HEAPCHECKENABLED | + BOINC_DIAG_MEMORYLEAKCHECKENABLED | + BOINC_DIAG_REDIRECTSTDERR | + BOINC_DIAG_REDIRECTSTDOUT | + BOINC_DIAG_TRACETOSTDOUT; + diagnostics_init( + dwDiagnosticsFlags, + "stdoutgui", + "stderrgui" + ); + + // Initialize the configuration storage module + m_pConfig = new wxConfig(GetAppName()); + wxConfigBase::Set(m_pConfig); + wxASSERT(NULL != m_pConfig); + + // Enable Logging and Trace Masks + m_pLog = new wxLogBOINC(); + wxLog::SetActiveTarget(m_pLog); + + m_pLog->AddTraceMask( wxT("Function Start/End") ); // Enable the in memory virtual file system for // storing images @@ -64,10 +87,6 @@ bool CBOINCGUIApp::OnInit() // Enable known image types wxImage::AddHandler(new wxXPMHandler); - // Commandline parsing is done in wxApp::OnInit() - if (!wxApp::OnInit()) - return false; - // Initialize the internationalization module m_pLocale = new wxLocale(); wxASSERT(NULL != m_pLocale); @@ -77,10 +96,9 @@ bool CBOINCGUIApp::OnInit() m_pLocale->AddCatalogLookupPathPrefix(wxT("locale")); m_pLocale->AddCatalog(GetAppName()); - // Initialize the configuration storage module - m_pConfig = new wxConfig(GetAppName()); - wxConfigBase::Set(m_pConfig); - wxASSERT(NULL != m_pConfig); + // Commandline parsing is done in wxApp::OnInit() + if (!wxApp::OnInit()) + return false; // Initialize the main document m_pDocument = new CMainDocument(); @@ -258,7 +276,7 @@ void CBOINCGUIApp::StartupBOINCCore() #ifdef __WXMSW__ // Append boinc.exe to the end of the strExecute string and get ready to rock - strExecute += wxT("\\boinc.exe"); + strExecute += wxT("\\boinc.exe -redirectio"); PROCESS_INFORMATION pi; STARTUPINFO si; diff --git a/clientgui/BOINCGUIApp.h b/clientgui/BOINCGUIApp.h index 19cd329c73..c7ed7ed1bf 100644 --- a/clientgui/BOINCGUIApp.h +++ b/clientgui/BOINCGUIApp.h @@ -25,6 +25,7 @@ #endif +#include "LogBOINC.h" #include "MainFrame.h" #include "MainDocument.h" #ifndef NOTASKBAR @@ -52,8 +53,9 @@ protected: wxInt32 StartupSystemIdleDetection(); wxInt32 ShutdownSystemIdleDetection(); - wxLocale* m_pLocale; wxConfig* m_pConfig; + wxLocale* m_pLocale; + wxLogBOINC* m_pLog; CMainFrame* m_pFrame; CMainDocument* m_pDocument; diff --git a/clientgui/LogBOINC.cpp b/clientgui/LogBOINC.cpp new file mode 100644 index 0000000000..34a85cde60 --- /dev/null +++ b/clientgui/LogBOINC.cpp @@ -0,0 +1,40 @@ +// 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 + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma implementation "LogBOINC.h" +#endif + +#include "stdwx.h" +#include "BOINCGUIApp.h" +#include "diagnostics.h" +#include "LogBOINC.h" + + +wxLogBOINC::wxLogBOINC() +{ + m_fp = stdout; +} + +void wxLogBOINC::DoLogString(const wxChar *szString, time_t t) +{ + diagnostics_cycle_logs(); + wxLogStderr::DoLogString(szString, t); +} + diff --git a/clientgui/LogBOINC.h b/clientgui/LogBOINC.h new file mode 100644 index 0000000000..227ea11c03 --- /dev/null +++ b/clientgui/LogBOINC.h @@ -0,0 +1,40 @@ +// 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 + +#ifndef _LOGBOINC_H_ +#define _LOGBOINC_H_ + +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "LogBOINC.cpp" +#endif + + +class wxLogBOINC : public wxLogStderr +{ + DECLARE_NO_COPY_CLASS(wxLogBOINC) + +public: + wxLogBOINC(); + +protected: + virtual void DoLogString(const wxChar *szString, time_t t); +}; + + +#endif \ No newline at end of file diff --git a/clientgui/Makefile.am b/clientgui/Makefile.am index 3f9a4ac71b..baa5ccdea7 100644 --- a/clientgui/Makefile.am +++ b/clientgui/Makefile.am @@ -16,6 +16,7 @@ boinc_gui_SOURCES = \ DlgAttachProject.cpp \ DlgConnection.cpp \ DlgOptions.cpp \ + LogBOINC.cpp \ MainDocument.cpp \ MainFrame.cpp \ stdwx.cpp \ diff --git a/clientgui/ViewMessages.cpp b/clientgui/ViewMessages.cpp index 1ce6b8df39..f58b0c27b3 100644 --- a/clientgui/ViewMessages.cpp +++ b/clientgui/ViewMessages.cpp @@ -197,6 +197,8 @@ CViewMessages::CViewMessages(wxNotebook* pNotebook) : CViewMessages::~CViewMessages() { + EmptyCache(); + if ( m_pMessageInfoAttr ) { delete m_pMessageInfoAttr; diff --git a/clientgui/ViewProjects.cpp b/clientgui/ViewProjects.cpp index e8ab450895..6e42d2157a 100644 --- a/clientgui/ViewProjects.cpp +++ b/clientgui/ViewProjects.cpp @@ -299,6 +299,7 @@ CViewProjects::CViewProjects(wxNotebook* pNotebook) : CViewProjects::~CViewProjects() { + EmptyCache(); } diff --git a/clientgui/ViewResources.cpp b/clientgui/ViewResources.cpp index 8edbf0b3aa..d92024ebd0 100644 --- a/clientgui/ViewResources.cpp +++ b/clientgui/ViewResources.cpp @@ -144,6 +144,7 @@ CViewResources::CViewResources(wxNotebook* pNotebook) : CViewResources::~CViewResources() { + EmptyCache(); } diff --git a/clientgui/ViewTransfers.cpp b/clientgui/ViewTransfers.cpp index 1cc9e6e144..530f1cc6a9 100644 --- a/clientgui/ViewTransfers.cpp +++ b/clientgui/ViewTransfers.cpp @@ -246,6 +246,7 @@ CViewTransfers::CViewTransfers(wxNotebook* pNotebook) : CViewTransfers::~CViewTransfers() { + EmptyCache(); } diff --git a/clientgui/ViewWork.cpp b/clientgui/ViewWork.cpp index 5cbe354a52..7a5f2cd6f1 100644 --- a/clientgui/ViewWork.cpp +++ b/clientgui/ViewWork.cpp @@ -273,6 +273,7 @@ CViewWork::CViewWork(wxNotebook* pNotebook) : CViewWork::~CViewWork() { + EmptyCache(); } diff --git a/clientgui/stdwx.h b/clientgui/stdwx.h index 63225c78b5..7b872afda3 100644 --- a/clientgui/stdwx.h +++ b/clientgui/stdwx.h @@ -125,6 +125,9 @@ // C++ headers +#ifdef __WXMSW__ +#include +#endif #include #include #include diff --git a/lib/diagnostics.C b/lib/diagnostics.C index ec1a36a0d2..7566e79ca1 100644 --- a/lib/diagnostics.C +++ b/lib/diagnostics.C @@ -40,83 +40,36 @@ #include "filesys.h" #include "util.h" -static int flags; + +#define MAX_STDERR_FILE_SIZE 2048*1024 +#define MAX_STDOUT_FILE_SIZE 2048*1024 + + +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; + #ifdef _WIN32 + LONG CALLBACK boinc_catch_signal(EXCEPTION_POINTERS *ExceptionInfo); int __cdecl boinc_message_reporting( int reportType, char *szMsg, int *retVal ); + #else + static void boinc_catch_signal(int signal); -//static void boinc_quit(int sig); + #endif -// initialize the diagnostics environment. +// stub function for initializing the diagnostics environment. // int boinc_init_diagnostics(int _flags) { - void* lpRetVal; - - flags = _flags; - - // Archive any old stderr.txt and stdout.txt files, if requested - if ( flags & BOINC_DIAG_ARCHIVESTDERR ) { - boinc_copy(BOINC_DIAG_STDERR, BOINC_DIAG_STDERROLD); - } - - if ( flags & BOINC_DIAG_ARCHIVESTDOUT) { - boinc_copy( BOINC_DIAG_STDOUT, BOINC_DIAG_STDOUTOLD ); - } - - - // Redirect stderr and/or stdout streams, if requested - if (flags & BOINC_DIAG_REDIRECTSTDERR ) { - lpRetVal = (void*) freopen(BOINC_DIAG_STDERR, "a", stderr); - if ( NULL == lpRetVal ) { - return ERR_FOPEN; - } - } - - if (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE ) { - lpRetVal = (void*) freopen(BOINC_DIAG_STDERR, "w", stderr); - if ( NULL == lpRetVal ) { - return ERR_FOPEN; - } - } - - if (flags & BOINC_DIAG_REDIRECTSTDOUT ) { - lpRetVal = (void*) freopen(BOINC_DIAG_STDOUT, "a", stdout); - if ( NULL == lpRetVal ) { - return ERR_FOPEN; - } - } - - if (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE ) { - lpRetVal = (void*) freopen(BOINC_DIAG_STDOUT, "w", stdout); - if ( NULL == lpRetVal ) { - return ERR_FOPEN; - } - } - - -#if defined(_WIN32) && defined(_DEBUG) - - _CrtSetReportHook( boinc_message_reporting ); - - if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED ) - SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); - - if (flags & BOINC_DIAG_HEAPCHECKENABLED ) - SET_CRT_DEBUG_FIELD( _CRTDBG_CHECK_EVERY_1024_DF ); - -#endif // defined(_WIN32) && defined(_DEBUG) - - - // Install unhandled exception filters and signal traps. - if ( BOINC_SUCCESS != boinc_install_signal_handlers() ) { - return ERR_SIGNAL_OP; - } - - return BOINC_SUCCESS; + return diagnostics_init( _flags, BOINC_DIAG_STDOUT, BOINC_DIAG_STDERR ); } @@ -149,6 +102,123 @@ int boinc_install_signal_handlers() { } +// initialize the diagnostics environment. +// +int diagnostics_init(int _flags, char* stdout_prefix, char* stderr_prefix) { + + flags = _flags; + 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); + + + // Check for invalid parameter combinations + if ( ( flags & BOINC_DIAG_REDIRECTSTDERR ) && ( flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE ) ) { + return ERR_INVALID_PARAM; + } + + if ( ( flags & BOINC_DIAG_REDIRECTSTDOUT ) && ( flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE ) ) { + return ERR_INVALID_PARAM; + } + + + // Archive any old stderr.txt and stdout.txt files, if requested + if ( flags & BOINC_DIAG_ARCHIVESTDERR ) { + boinc_copy(stderr_log, stderr_archive); + } + + if ( flags & BOINC_DIAG_ARCHIVESTDOUT) { + boinc_copy( stdout_log, stdout_archive ); + } + + + // Redirect stderr and/or stdout streams, if requested + if (flags & BOINC_DIAG_REDIRECTSTDERR ) { + stderr_file = freopen(stderr_log, "a", stderr); + if ( NULL == stderr_file ) { + return ERR_FOPEN; + } + } + + if (flags & BOINC_DIAG_REDIRECTSTDERROVERWRITE ) { + stderr_file = freopen(stderr_log, "w", stderr); + if ( NULL == stderr_file ) { + return ERR_FOPEN; + } + } + + if (flags & BOINC_DIAG_REDIRECTSTDOUT ) { + stdout_file = freopen(stdout_log, "a", stdout); + if ( NULL == stdout_file ) { + return ERR_FOPEN; + } + } + + if (flags & BOINC_DIAG_REDIRECTSTDOUTOVERWRITE ) { + stdout_file = freopen(stdout_log, "w", stdout); + if ( NULL == stdout_file ) { + return ERR_FOPEN; + } + } + + +#if defined(_WIN32) && defined(_DEBUG) + + _CrtSetReportHook( boinc_message_reporting ); + + if (flags & BOINC_DIAG_MEMORYLEAKCHECKENABLED ) + SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); + + if (flags & BOINC_DIAG_HEAPCHECKENABLED ) + SET_CRT_DEBUG_FIELD( _CRTDBG_CHECK_EVERY_1024_DF ); + +#endif // defined(_WIN32) && defined(_DEBUG) + + + // Install unhandled exception filters and signal traps. + if ( BOINC_SUCCESS != boinc_install_signal_handlers() ) { + return ERR_SIGNAL_OP; + } + + return BOINC_SUCCESS; +} + + +// Cycle the log files at regular events. +// +int diagnostics_cycle_logs() { + double f_size; + + fflush(stdout); + fflush(stderr); + + // If the stderr.txt or stdout.txt files are too big, cycle them + // + if (flags & BOINC_DIAG_REDIRECTSTDERR) { + file_size(stderr_log, f_size); + if (MAX_STDERR_FILE_SIZE < f_size) { + fclose( stderr_file ); + boinc_copy(stderr_log, stderr_archive); + stderr_file = freopen( stderr_log, "w", stderr ); + if ( NULL == stderr_file ) return ERR_FOPEN; + } + } + + if (flags & BOINC_DIAG_REDIRECTSTDOUT) { + file_size(stdout_log, f_size); + if (MAX_STDOUT_FILE_SIZE < f_size) { + fclose( stdout_file ); + boinc_copy( stdout_log, stdout_archive ); + stdout_file = freopen( stdout_log, "w", stdout ); + if ( NULL == stdout_file ) return ERR_FOPEN; + } + } + + return BOINC_SUCCESS; +} + + #ifdef _WIN32 // Used to unwind the stack and spew the callstack to stderr. Terminate the @@ -495,13 +565,6 @@ void boinc_catch_signal(int signal) { } -/* -void boinc_quit(int sig) { - signal(SIGQUIT, boinc_quit); // reset signal - time_to_quit = true; -} -*/ - #endif const char *BOINC_RCSID_4967ad204c = "$Id$"; diff --git a/lib/diagnostics.h b/lib/diagnostics.h index 4401946dde..4dfb07ecbe 100644 --- a/lib/diagnostics.h +++ b/lib/diagnostics.h @@ -48,10 +48,8 @@ // filenames // -#define BOINC_DIAG_STDERR "stderr.txt" -#define BOINC_DIAG_STDERROLD "stderr.old" -#define BOINC_DIAG_STDOUT "stdout.txt" -#define BOINC_DIAG_STDOUTOLD "stdout.old" +#define BOINC_DIAG_STDERR "stderr" +#define BOINC_DIAG_STDOUT "stdout" #ifdef _WIN32 @@ -103,8 +101,10 @@ void boinc_info_release(const char *pszFormat, ...); #ifdef __cplusplus extern "C" { #endif // __cplusplus - extern void boinc_set_signal_handler(int sig, void(*handler)(int)); - extern void boinc_set_signal_handler_force(int sig, void(*handler)(int)); + +extern void boinc_set_signal_handler(int sig, void(*handler)(int)); +extern void boinc_set_signal_handler_force(int sig, void(*handler)(int)); + #ifdef __cplusplus } #endif // __cplusplus @@ -136,6 +136,9 @@ extern int boinc_init_diagnostics(int flags); extern int boinc_finish_diag(); extern int boinc_install_signal_handlers(); +extern int diagnostics_init(int flags, char* stdout_prefix, char* stderr_prefix); +extern int diagnostics_cycle_logs(); + #ifdef __cplusplus } #endif diff --git a/win_build/BOINCGUI.vcproj b/win_build/BOINCGUI.vcproj index 7fb365d1b5..6033fdd415 100644 --- a/win_build/BOINCGUI.vcproj +++ b/win_build/BOINCGUI.vcproj @@ -159,6 +159,21 @@ + + + + + + + + @@ -217,6 +232,9 @@ CompileAs="2"/> + + @@ -310,6 +328,9 @@ CompileAs="2"/> + + + + @@ -422,6 +446,9 @@ + + @@ -446,6 +473,9 @@ + +