From e3d445599cd5ef3d6fb331b4089001fef6ef9690 Mon Sep 17 00:00:00 2001 From: Tristan Chabredier Date: Tue, 21 Aug 2007 09:04:16 +0000 Subject: [PATCH] 2007-08-21 [wwp] 2.10.0cvs140 * src/main.c * src/common/utils.h Route glib's stdout/stderr messages to a log file (Windows only), instead of loosing them. --- ChangeLog | 7 +++ PATCHSETS | 1 + configure.ac | 2 +- src/common/utils.h | 8 +++ src/main.c | 139 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 155 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f9256258..32a3d780d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-08-21 [wwp] 2.10.0cvs140 + + * src/main.c + * src/common/utils.h + Route glib's stdout/stderr messages to a log file (Windows only), + instead of loosing them. + 2007-08-21 [paul] 2.10.0cvs139 * src/mainwindow.c diff --git a/PATCHSETS b/PATCHSETS index 6578ade83..774ede0bb 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -2794,3 +2794,4 @@ ( cvs diff -u -r 1.2.2.12 -r 1.2.2.13 src/ldapctrl.c; ) > 2.10.0cvs137.patchset ( cvs diff -u -r 1.61.2.65 -r 1.61.2.66 src/account.c; cvs diff -u -r 1.105.2.107 -r 1.105.2.108 src/prefs_account.c; cvs diff -u -r 1.49.2.32 -r 1.49.2.33 src/prefs_account.h; ) > 2.10.0cvs138.patchset ( cvs diff -u -r 1.274.2.205 -r 1.274.2.206 src/mainwindow.c; cvs diff -u -r 1.94.2.145 -r 1.94.2.146 src/messageview.c; ) > 2.10.0cvs139.patchset +( cvs diff -u -r 1.115.2.162 -r 1.115.2.163 src/main.c; cvs diff -u -r 1.20.2.48 -r 1.20.2.49 src/common/utils.h; ) > 2.10.0cvs140.patchset diff --git a/configure.ac b/configure.ac index 8c6c55e19..a9506a2b2 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=10 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=139 +EXTRA_VERSION=140 EXTRA_RELEASE= EXTRA_GTK2_VERSION= diff --git a/src/common/utils.h b/src/common/utils.h index 29b8ca90f..0ddd40990 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -108,6 +108,14 @@ gint g_chmod (const gchar *path, if (change_dir(dir) < 0) return val; \ } +#define CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(dir, val, code) \ +{ \ + if (change_dir(dir) < 0) { \ + code \ + return val; \ + } \ +} + #define Xalloca(ptr, size, iffail) \ { \ if ((ptr = alloca(size)) == NULL) { \ diff --git a/src/main.c b/src/main.c index f3458725d..ca78c5e6f 100644 --- a/src/main.c +++ b/src/main.c @@ -664,6 +664,97 @@ static void main_vol_unmount_cb(GnomeVFSVolumeMonitor *vfs, GnomeVFSVolume *vol, } #endif +#ifdef G_OS_WIN32 +static FILE* win32_debug_fp=NULL; +static guint win32_log_handler_app_id; +static guint win32_log_handler_glib_id; +static guint win32_log_handler_gtk_id; + +static void win32_print_stdout(const gchar *string) +{ + if (win32_debug_fp) { + fprintf(win32_debug_fp, string); + fflush(win32_debug_fp); + } +} + +static void win32_print_stderr(const gchar *string) +{ + if (win32_debug_fp) { + fprintf(win32_debug_fp, string); + fflush(win32_debug_fp); + } +} + +static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data) +{ + if (win32_debug_fp) { + const gchar* type; + + switch(log_level & G_LOG_LEVEL_MASK) + { + case G_LOG_LEVEL_ERROR: + type="error"; + break; + case G_LOG_LEVEL_CRITICAL: + type="critical"; + break; + case G_LOG_LEVEL_WARNING: + type="warning"; + break; + case G_LOG_LEVEL_MESSAGE: + type="message"; + break; + case G_LOG_LEVEL_INFO: + type="info"; + break; + case G_LOG_LEVEL_DEBUG: + type="debug"; + break; + default: + type="N/A"; + } + if (log_domain) + fprintf(win32_debug_fp, "%s: %s: %s", log_domain, type, message); + else + fprintf(win32_debug_fp, "%s: %s", type, message); + fflush(win32_debug_fp); + } +} + +static void win32_open_log(void) +{ + if (is_file_exist("claws-win32.log")) { + if (rename_force("claws-win32.log", "claws-win32.log.bak") < 0) + FILE_OP_ERROR("claws-win32.log", "rename"); + } + win32_debug_fp = fopen("claws-win32.log", "w"); + if (win32_debug_fp) + { + g_set_print_handler(win32_print_stdout); + g_set_printerr_handler(win32_print_stdout); + win32_log_handler_app_id = g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL + | G_LOG_FLAG_RECURSION, win32_log, NULL); + win32_log_handler_glib_id = g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL + | G_LOG_FLAG_RECURSION, win32_log, NULL); + win32_log_handler_gtk_id = g_log_set_handler("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL + | G_LOG_FLAG_RECURSION, win32_log, NULL); + } +} + +static void win32_close_log(void) +{ + if (win32_debug_fp) + { + g_log_remove_handler("", win32_log_handler_app_id); + g_log_remove_handler("GLib", win32_log_handler_glib_id); + g_log_remove_handler("Gtk", win32_log_handler_gtk_id); + fclose(win32_debug_fp); + win32_debug_fp=NULL; + } +} +#endif + int main(int argc, char *argv[]) { #ifdef MAEMO @@ -682,7 +773,13 @@ int main(int argc, char *argv[]) sc_starting = TRUE; +#ifdef G_OS_WIN32 + win32_open_log(); +#endif if (!claws_init(&argc, &argv)) { +#ifdef G_OS_WIN32 + win32_close_log(); +#endif return 0; } @@ -697,6 +794,9 @@ int main(int argc, char *argv[]) gtk_set_locale(); gtk_init(&argc, &argv); crash_main(cmd.crash_params); +#ifdef G_OS_WIN32 + win32_close_log(); +#endif return 0; } crash_install_handlers(); @@ -754,6 +854,9 @@ int main(int argc, char *argv[]) "currently available. This will cause " "crashes. You need to upgrade GTK+ or " "recompile Claws Mail.")); +#ifdef G_OS_WIN32 + win32_close_log(); +#endif exit(1); } #else @@ -763,6 +866,9 @@ int main(int argc, char *argv[]) "currently available. This will cause " "crashes. You need to recompile " "Claws Mail.")); +#ifdef G_OS_WIN32 + win32_close_log(); +#endif exit(1); } #endif @@ -776,7 +882,11 @@ int main(int argc, char *argv[]) gtk_rc_parse(userrc); g_free(userrc); +#ifdef G_OS_WIN32 + CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log();); +#else CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1); +#endif /* no config dir exists. See if we can migrate an old config. */ if (!is_dir_exist(RC_DIR)) { @@ -804,9 +914,13 @@ int main(int argc, char *argv[]) /* If migration failed or the user didn't want to do it, * we create a new one (and we'll hit wizard later). */ - if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0) + if (r == FALSE && !is_dir_exist(RC_DIR) && make_dir(RC_DIR) < 0) { +#ifdef G_OS_WIN32 + win32_close_log(); +#endif exit(1); } + } if (!is_file_exist(RC_DIR G_DIR_SEPARATOR_S COMMON_RC) && @@ -827,7 +941,11 @@ int main(int argc, char *argv[]) gtk_accel_map_load (userrc); g_free(userrc); +#ifdef G_OS_WIN32 + CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_rc_dir(), 1, win32_close_log();); +#else CHDIR_RETURN_VAL_IF_FAIL(get_rc_dir(), 1); +#endif MAKE_DIR_IF_NOT_EXIST(get_mail_base_dir()); MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir()); @@ -856,7 +974,11 @@ int main(int argc, char *argv[]) } set_log_file(LOG_DEBUG_FILTERING, "filtering.log"); +#ifdef G_OS_WIN32 + CHDIR_EXEC_CODE_RETURN_VAL_IF_FAIL(get_home_dir(), 1, win32_close_log();); +#else CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1); +#endif folder_system_init(); prefs_common_read_config(); @@ -956,6 +1078,9 @@ int main(int argc, char *argv[]) if (!run_wizard(mainwin, TRUE)) { if (asked_for_migration) remove_dir_recursive(RC_DIR); +#ifdef G_OS_WIN32 + win32_close_log(); +#endif exit(1); } main_window_reflect_prefs_all_now(); @@ -967,11 +1092,17 @@ int main(int argc, char *argv[]) if (!run_wizard(mainwin, FALSE)) { if (asked_for_migration) remove_dir_recursive(RC_DIR); +#ifdef G_OS_WIN32 + win32_close_log(); +#endif exit(1); } account_read_config_all(); if(!account_get_list()) { exit_claws(mainwin); +#ifdef G_OS_WIN32 + win32_close_log(); +#endif exit(1); } } @@ -1079,6 +1210,9 @@ int main(int argc, char *argv[]) "external plugin. Please reinstall the " "plugin and try again.")); exit_claws(mainwin); +#ifdef G_OS_WIN32 + win32_close_log(); +#endif exit(1); } } @@ -1172,6 +1306,9 @@ int main(int argc, char *argv[]) #ifdef MAEMO osso_deinitialize(osso_context); +#endif +#ifdef G_OS_WIN32 + win32_close_log(); #endif exit_claws(mainwin); -- 2.25.1