From e08e2bd87aceafc2a34d72ca3fd362f2f2ea90eb Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Fri, 28 Jul 2017 03:56:02 +0100 Subject: [PATCH 1/5] Don't compute log_dir_create_mode in three different places. Signed-off-by: Edward Tomasz Napierala --- src/core/log.c | 5 ++--- src/core/log.h | 2 ++ src/core/rawlog.c | 9 +-------- src/fe-common/core/fe-log.c | 9 --------- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index 6af1effc..cee1dab5 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -33,6 +33,8 @@ #define DEFAULT_LOG_FILE_CREATE_MODE 600 GSList *logs; +int log_file_create_mode; +int log_dir_create_mode; static const char *log_item_types[] = { "target", @@ -42,8 +44,6 @@ static const char *log_item_types[] = { }; static char *log_timestamp; -static int log_file_create_mode; -static int log_dir_create_mode; static int rotate_tag; static int log_item_str2type(const char *type) @@ -562,7 +562,6 @@ static void read_settings(void) log_timestamp = g_strdup(settings_get_str("log_timestamp")); log_file_create_mode = octal2dec(settings_get_int("log_create_mode")); - log_dir_create_mode = log_file_create_mode; if (log_file_create_mode & 0400) log_dir_create_mode |= 0100; if (log_file_create_mode & 0040) log_dir_create_mode |= 0010; diff --git a/src/core/log.h b/src/core/log.h index fae872c7..5a07859b 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -35,6 +35,8 @@ struct _LOG_REC { }; extern GSList *logs; +extern int log_file_create_mode; +extern int log_dir_create_mode; /* Create log record - you still need to call log_update() to actually add it into log list */ diff --git a/src/core/rawlog.c b/src/core/rawlog.c index 5927e730..2192e256 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -20,6 +20,7 @@ #include "module.h" #include "rawlog.h" +#include "log.h" #include "modules.h" #include "signals.h" #include "commands.h" @@ -31,8 +32,6 @@ static int rawlog_lines; static int signal_rawlog; -static int log_file_create_mode; -static int log_dir_create_mode; RAWLOG_REC *rawlog_create(void) { @@ -174,12 +173,6 @@ void rawlog_set_size(int lines) static void read_settings(void) { rawlog_set_size(settings_get_int("rawlog_lines")); - log_file_create_mode = octal2dec(settings_get_int("log_create_mode")); - log_dir_create_mode = log_file_create_mode; - if (log_file_create_mode & 0400) log_dir_create_mode |= 0100; - if (log_file_create_mode & 0040) log_dir_create_mode |= 0010; - if (log_file_create_mode & 0004) log_dir_create_mode |= 0001; - } static void cmd_rawlog(const char *data, SERVER_REC *server, void *item) diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 5bc5c4e1..37b29990 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -49,8 +49,6 @@ static THEME_REC *log_theme; static int skip_next_printtext; static char *log_theme_name; -static int log_dir_create_mode; - static char **autolog_ignore_targets; static char *log_colorizer_strip(const char *str) @@ -676,7 +674,6 @@ static void sig_theme_destroyed(THEME_REC *theme) static void read_settings(void) { int old_autolog = autolog_level; - int log_file_create_mode; g_free_not_null(autolog_path); autolog_path = g_strdup(settings_get_str("autolog_path")); @@ -704,12 +701,6 @@ static void read_settings(void) log_theme = log_theme_name == NULL ? NULL : theme_load(log_theme_name); - log_file_create_mode = octal2dec(settings_get_int("log_create_mode")); - log_dir_create_mode = log_file_create_mode; - if (log_file_create_mode & 0400) log_dir_create_mode |= 0100; - if (log_file_create_mode & 0040) log_dir_create_mode |= 0010; - if (log_file_create_mode & 0004) log_dir_create_mode |= 0001; - if (autolog_ignore_targets != NULL) g_strfreev(autolog_ignore_targets); From 42b5e89f6e9fba17111f67441e25db38a737a3bd Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Fri, 28 Jul 2017 04:49:14 +0100 Subject: [PATCH 2/5] Add missing diagnostics for rawlog open(). Signed-off-by: Edward Tomasz Napierala --- src/core/rawlog.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/rawlog.c b/src/core/rawlog.c index 2192e256..d929682a 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -128,6 +128,9 @@ void rawlog_open(RAWLOG_REC *rawlog, const char *fname) path = convert_home(fname); rawlog->handle = open(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode); + if (rawlog->handle == -1) { + g_warning("rawlog open() failed: %s", strerror(errno)); + } g_free(path); rawlog_dump(rawlog, rawlog->handle); From 08dc6734b90389c357c73544023ec614e43b0860 Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Sat, 29 Jul 2017 09:25:51 +0100 Subject: [PATCH 3/5] When rawlog open fails, there's no point in trying to write. Don't. Signed-off-by: Edward Tomasz Napierala --- src/core/rawlog.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/rawlog.c b/src/core/rawlog.c index d929682a..43f140f3 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -128,13 +128,15 @@ void rawlog_open(RAWLOG_REC *rawlog, const char *fname) path = convert_home(fname); rawlog->handle = open(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode); - if (rawlog->handle == -1) { - g_warning("rawlog open() failed: %s", strerror(errno)); - } g_free(path); + if (rawlog->handle == -1) { + g_warning("rawlog open() failed: %s", strerror(errno)); + return; + } + rawlog_dump(rawlog, rawlog->handle); - rawlog->logging = rawlog->handle != -1; + rawlog->logging = TRUE; } void rawlog_close(RAWLOG_REC *rawlog) From 2914498b291ea0ca432a320004aa3d2499e50eb5 Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Sat, 29 Jul 2017 10:42:53 +0100 Subject: [PATCH 4/5] Consistency: use FALSE instead of 0. Signed-off-by: Edward Tomasz Napierala --- src/core/rawlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/rawlog.c b/src/core/rawlog.c index 43f140f3..2ec155fa 100644 --- a/src/core/rawlog.c +++ b/src/core/rawlog.c @@ -144,7 +144,7 @@ void rawlog_close(RAWLOG_REC *rawlog) if (rawlog->logging) { write_buffer_flush(); close(rawlog->handle); - rawlog->logging = 0; + rawlog->logging = FALSE; } } From 2907a82b446d9d0a25157aa4ab560b49853f80d2 Mon Sep 17 00:00:00 2001 From: Edward Tomasz Napierala Date: Sat, 29 Jul 2017 12:32:15 +0100 Subject: [PATCH 5/5] Fix vertical alignment in ./configure --help output. Signed-off-by: Edward Tomasz Napierala --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 459d3a2d..c7c8edef 100644 --- a/configure.ac +++ b/configure.ac @@ -158,7 +158,7 @@ AC_ARG_ENABLE(true-color, want_truecolor=no) AC_ARG_ENABLE(gregex, -[ --disable-gregex Build without GRegex (fall back to regex.h)], +[ --disable-gregex Build without GRegex (fall back to regex.h)], if test x$enableval = xno ; then want_gregex=no else