diff options
-rw-r--r-- | amiga/gui.c | 5 | ||||
-rw-r--r-- | atari/gui.c | 6 | ||||
-rw-r--r-- | beos/gui.cpp | 29 | ||||
-rw-r--r-- | cocoa/NetsurfApp.m | 5 | ||||
-rw-r--r-- | desktop/gui.h | 4 | ||||
-rw-r--r-- | desktop/netsurf.c | 9 | ||||
-rw-r--r-- | framebuffer/gui.c | 18 | ||||
-rw-r--r-- | gtk/gui.c | 19 | ||||
-rw-r--r-- | monkey/main.c | 16 | ||||
-rw-r--r-- | riscos/gui.c | 18 | ||||
-rw-r--r-- | utils/log.c | 24 | ||||
-rw-r--r-- | windows/main.c | 15 |
12 files changed, 128 insertions, 40 deletions
diff --git a/amiga/gui.c b/amiga/gui.c index 97e45e54b..33cd1bcf9 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -929,6 +929,11 @@ int main(int argc, char** argv) amiga_plugin_hack_init(); amiga_datatypes_init(); + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(NULL, &argc, argv); + netsurf_init(&argc, &argv, current_user_options, messages); amiga_icon_init(); diff --git a/atari/gui.c b/atari/gui.c index f125142af..776e30a25 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -1037,6 +1037,7 @@ int main(int argc, char** argv) nsurl *url; nserror error; + /* @todo logging file descriptor update belongs in a nslog_init callback */ setbuf(stderr, NULL); setbuf(stdout, NULL); #ifdef WITH_DBG_LOGFILE @@ -1053,6 +1054,11 @@ int main(int argc, char** argv) atari_find_resource((char*)&messages, "messages", "res/messages"); atari_find_resource((char*)&options, "Choices", "Choices"); + /* initialise logging - not fatal if it fails but not much we can + * do about it + */ + nslog_init(NULL, &argc, argv); + LOG(("Initialising core...")); netsurf_init(&argc, &argv, options, messages); diff --git a/beos/gui.cpp b/beos/gui.cpp index b2f40431d..091346605 100644 --- a/beos/gui.cpp +++ b/beos/gui.cpp @@ -398,11 +398,20 @@ static void gui_init2(int argc, char** argv) } } +/** + * Ensures output logging stream is correctly configured + */ +static bool nslog_stream_configure(FILE *fptr) +{ + /* set log stream to be non-buffering */ + setbuf(fptr, NULL); + + return true; +} + /** Normal entry point from OS */ int main(int argc, char** argv) { - setbuf(stderr, NULL); - BPath options; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { options.Append("x-vnd.NetSurf"); @@ -416,11 +425,16 @@ int main(int argc, char** argv) const char* messages = "/boot/apps/netsurf/res/en/Messages"; + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + /* initialise netsurf */ netsurf_init(&argc, &argv, options.Path(), messages); - gui_init(argc, argv); - gui_init2(argc, argv); + gui_init(argc, argv); + gui_init2(argc, argv); netsurf_main_loop(); @@ -432,8 +446,6 @@ int main(int argc, char** argv) /** called when replicated from NSBaseView::Instantiate() */ int gui_init_replicant(int argc, char** argv) { - setbuf(stderr, NULL); - BPath options; if (find_directory(B_USER_SETTINGS_DIRECTORY, &options, true) == B_OK) { options.Append("x-vnd.NetSurf"); @@ -441,6 +453,11 @@ int gui_init_replicant(int argc, char** argv) const char* messages = "/boot/apps/netsurf/res/en/Messages"; + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + /* initialise netsurf */ netsurf_init(&argc, &argv, options.Path(), messages); diff --git a/cocoa/NetsurfApp.m b/cocoa/NetsurfApp.m index 19d843734..1c288e861 100644 --- a/cocoa/NetsurfApp.m +++ b/cocoa/NetsurfApp.m @@ -182,6 +182,11 @@ int main( int argc, char **argv ) const char * const messages = [[[NSBundle mainBundle] pathForResource: @"Messages" ofType: @""] UTF8String]; const char * const options = cocoa_get_options_file(); + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(NULL, &argc, argv); + netsurf_init(&argc, &argv, options, messages); /* Initialise filename allocator */ diff --git a/desktop/gui.h b/desktop/gui.h index f4b8b7215..dc190952b 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -64,10 +64,6 @@ struct form_control; #include "desktop/search.h" #include "utils/errors.h" -/** \todo remove these when each frontend calls nslog_init */ -#include <stdio.h> -bool nslog_ensure(FILE *fptr); - void gui_poll(bool active); void gui_quit(void); diff --git a/desktop/netsurf.c b/desktop/netsurf.c index a67321191..b6e342c58 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -143,15 +143,6 @@ nserror netsurf_init(int *pargc, signal(SIGPIPE, SIG_IGN); #endif -#ifndef HAVE_STDOUT - ret = nslog_init(nslog_ensure, pargc, *pargv); -#else - ret = nslog_init(NULL, pargc, *pargv); -#endif - - if (ret != NSERROR_OK) - return ret; - LOG(("version '%s'", netsurf_version)); if (uname(&utsname) < 0) LOG(("Failed to extract machine information")); diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 3ceb81479..4277557b4 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -516,6 +516,17 @@ gui_init(int argc, char** argv) urldb_load_cookies(nsoption_charp(cookie_file)); } +/** + * Ensures output logging stream is correctly configured + */ +static bool nslog_stream_configure(FILE *fptr) +{ + /* set log stream to be non-buffering */ + setbuf(fptr, NULL); + + return true; +} + /** Entry point from OS. * * /param argc The number of arguments in the string vector. @@ -531,13 +542,16 @@ main(int argc, char** argv) nsurl *url; nserror error; - setbuf(stderr, NULL); - respaths = fb_init_resource(NETSURF_FB_RESPATH":"NETSURF_FB_FONTPATH); options = filepath_find(respaths, "Choices"); messages = filepath_find(respaths, "messages"); + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + netsurf_init(&argc, &argv, options, messages); free(messages); @@ -515,6 +515,17 @@ static void nsgtk_check_homedir(void) } /** + * Ensures output logging stream is correctly configured + */ +static bool nslog_stream_configure(FILE *fptr) +{ + /* set log stream to be non-buffering */ + setbuf(fptr, NULL); + + return true; +} + +/** * Main entry point from OS. */ int main(int argc, char** argv) @@ -529,12 +540,14 @@ int main(int argc, char** argv) gtk_init(&argc, &argv); - /* set standard error to be non-buffering */ - setbuf(stderr, NULL); - options = filepath_find(respaths, "Choices"); messages = filepath_find(respaths, "Messages"); + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + netsurf_init(&argc, &argv, options, messages); free(messages); diff --git a/monkey/main.c b/monkey/main.c index 03421ef03..26d6b321f 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -97,6 +97,17 @@ void gui_options_init_defaults(void) /* Set defaults for absent option strings */ } +/** + * Ensures output logging stream is correctly configured + */ +static bool nslog_stream_configure(FILE *fptr) +{ + /* set log stream to be non-buffering */ + setbuf(fptr, NULL); + + return true; +} + int main(int argc, char **argv) { @@ -115,6 +126,11 @@ main(int argc, char **argv) options = filepath_find(respaths, "Choices"); messages = filepath_find(respaths, "Messages"); + /* initialise logging. Not fatal if it fails but not much we can do + * about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + netsurf_init(&argc, &argv, options, messages); free(messages); diff --git a/riscos/gui.c b/riscos/gui.c index 53f281dd8..bca2a701a 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -799,6 +799,17 @@ static void gui_init2(int argc, char** argv) free(url); } +/** + * Ensures output logging stream is correctly configured + */ +static bool nslog_stream_configure(FILE *fptr) +{ + /* set log stream to be non-buffering */ + setbuf(fptr, NULL); + + return true; +} + /** Normal entry point from OS */ int main(int argc, char** argv) { @@ -809,8 +820,6 @@ int main(int argc, char** argv) int used = -1; /* slightly better with older OSLib versions */ os_error *error; - setbuf(stderr, NULL); - /* Consult NetSurf$Logging environment variable to decide if logging * is required. */ error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING, @@ -828,6 +837,11 @@ int main(int argc, char** argv) } } + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + /* Pass a NULL pointer for Messages path, because until the Choices * are loaded in netsurf_init, we don't know the Messages path. */ netsurf_init(&argc, &argv, "NetSurf:Choices", NULL); diff --git a/utils/log.c b/utils/log.c index 96a6d3c5b..2aa39ee41 100644 --- a/utils/log.c +++ b/utils/log.c @@ -31,9 +31,9 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) { nserror ret = NSERROR_OK; - if (((*pargc) > 1) && - (argv[1][0] == '-') && - (argv[1][1] == 'v') && + if (((*pargc) > 1) && + (argv[1][0] == '-') && + (argv[1][1] == 'v') && (argv[1][2] == 0)) { int argcmv; for (argcmv = 2; argcmv < (*pargc); argcmv++) { @@ -43,15 +43,17 @@ nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv) /* ensure we actually show logging */ verbose_log = true; - - /* ensure stderr is available */ - if (ensure != NULL) { - if (ensure(stderr) == false) { - /* failed to ensure output */ - ret = NSERROR_INIT_FAILED; - } - } } + + /* ensure output file handle is correctly configured */ + if ((verbose_log == true) && + (ensure != NULL) && + (ensure(stderr) == false)) { + /* failed to ensure output configuration */ + ret = NSERROR_INIT_FAILED; + verbose_log = false; + } + return ret; } diff --git a/windows/main.c b/windows/main.c index 19f71dd33..3ead210c7 100644 --- a/windows/main.c +++ b/windows/main.c @@ -66,9 +66,9 @@ void gui_quit(void) } /** - * Ensures output stdio stream is available + * Ensures output logging stream is available */ -bool nslog_ensure(FILE *fptr) +static bool nslog_ensure(FILE *fptr) { /* mwindows compile flag normally invalidates standard io unless * already redirected @@ -136,8 +136,17 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd) options_file_location = filepath_find(respaths, "preferences"); + /* initialise logging - not fatal if it fails but not much we + * can do about it + */ + nslog_init(nslog_ensure, &argc, argv); + /* initialise netsurf */ - netsurf_init(&argc, &argv, options_file_location, messages); + ret = netsurf_init(&argc, &argv, options_file_location, messages); + if (ret != NSERROR_OK) { + free(options_file_location); + return 1; + } free(messages); |