From 18a837c55bc25ebdd6ad25055bd8ae446dc57b5e Mon Sep 17 00:00:00 2001 From: Tom Fitzhenry Date: Mon, 13 Apr 2020 00:43:37 +1000 Subject: [PATCH] core: log to stdout, if headless Fixes https://github.com/weechat/weechat/issues/1475 . --- ChangeLog.adoc | 1 + src/core/wee-log.c | 11 +++++++++-- src/core/weechat.c | 1 + src/core/weechat.h | 1 + src/gui/curses/headless/main.c | 8 ++++---- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index da99b6d620d..83c8be40353 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -20,6 +20,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] New features:: + * core: weechat-headless logs to stdout rather than ~/.weechat/weechat.log (issue #1475) * buflist: evaluate option buflist.look.sort so that sort can be customized for each of the three buflist bar items (issue #1465) * relay: add command "handshake" in weechat relay protocol and nonce to prevent replay attacks, add options relay.network.password_hash_algo, relay.network.password_hash_iterations, relay.network.nonce_size (issue #1474) * relay: add option relay.network.auth_timeout diff --git a/src/core/wee-log.c b/src/core/wee-log.c index ab441e6cf42..a08f1d2762a 100644 --- a/src/core/wee-log.c +++ b/src/core/wee-log.c @@ -68,17 +68,24 @@ log_open (const char *filename, const char *mode) if (weechat_log_file) return 0; - if (filename) + if (weechat_headless && !weechat_daemon) + { + weechat_log_file = stdout; + } + else if (filename) + { weechat_log_filename = strdup (filename); + weechat_log_file = fopen (weechat_log_filename, mode); + } else { filename_length = strlen (weechat_home) + 64; weechat_log_filename = malloc (filename_length); snprintf (weechat_log_filename, filename_length, "%s/%s", weechat_home, WEECHAT_LOG_NAME); + weechat_log_file = fopen (weechat_log_filename, mode); } - weechat_log_file = fopen (weechat_log_filename, mode); if (!weechat_log_file) { free (weechat_log_filename); diff --git a/src/core/weechat.c b/src/core/weechat.c index 04b09da0ce4..fd90dbf0679 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -88,6 +88,7 @@ #define OPTION_NO_GCRYPT 1002 int weechat_headless = 0; /* 1 if running headless (no GUI) */ +int weechat_daemon = 0; /* 1 if daemonized (no foreground) */ int weechat_debug_core = 0; /* debug level for core */ char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0])*/ int weechat_upgrading = 0; /* =1 if WeeChat is upgrading */ diff --git a/src/core/weechat.h b/src/core/weechat.h index 274d5439215..39917851ff2 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -100,6 +100,7 @@ struct t_weelist; /* global variables and functions */ extern int weechat_headless; +extern int weechat_daemon; extern int weechat_debug_core; extern char *weechat_argv0; extern int weechat_upgrading; diff --git a/src/gui/curses/headless/main.c b/src/gui/curses/headless/main.c index 4bb859857b0..99df53d9976 100644 --- a/src/gui/curses/headless/main.c +++ b/src/gui/curses/headless/main.c @@ -88,7 +88,7 @@ daemonize () int main (int argc, char *argv[]) { - int i, daemon; + int i; weechat_init_gettext (); @@ -104,16 +104,16 @@ main (int argc, char *argv[]) * If "--daemon" is received in command line arguments, * daemonize the process. */ - daemon = 0; + weechat_daemon = 0; for (i = 1; i < argc; i++) { if (strcmp (argv[i], "--daemon") == 0) { - daemon = 1; + weechat_daemon = 1; break; } } - if (daemon) + if (weechat_daemon) daemonize (); /* init, main loop and end */