For master: 0001: Fix uninitialised variables in lib. 0002: Remove "-blackout" option. 0003: Docuement -v and alias it to --verbose. 0004: Don't list all options in the SYNOPSIS. 0005: Change getpwuid.c interface (for next patch) 0006: Implement -o/--output-logfile option. If given, use that logfile (abs or relative path) If the path is just "-", use stderr If not present use file from env variable If not presen, use default.
fvwm -v -o - ... # to stderr fvwm -v -o //home/foo/bar # to file The patch also fixes a memory leak. Ciao Dominik ^_^ ^_^ -- Dominik Vogt
From c81eb2cf991a5af850850ecf87d38bf6851bd788 Mon Sep 17 00:00:00 2001 From: Dominik Vogt <dominik.v...@gmx.de> Date: Sat, 20 Nov 2021 00:31:31 +0100 Subject: [PATCH 1/6] Fix uninitialised varibles. --- libs/FScreen.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libs/FScreen.c b/libs/FScreen.c index 32ee78a7..ffe4d4bb 100644 --- a/libs/FScreen.c +++ b/libs/FScreen.c @@ -806,10 +806,10 @@ void FScreenTranslateCoordinates( int FScreenClipToScreen(fscreen_scr_arg *arg, fscreen_scr_t screen, int *x, int *y, int w, int h) { - int sx; - int sy; - int sw; - int sh; + int sx = 0; + int sy = 0; + int sw = 0; + int sh = 0; int lx = (x) ? *x : 0; int ly = (y) ? *y : 0; int x_grav = GRAV_POS; @@ -852,10 +852,10 @@ int FScreenClipToScreen(fscreen_scr_arg *arg, fscreen_scr_t screen, void FScreenCenterOnScreen(fscreen_scr_arg *arg, fscreen_scr_t screen, int *x, int *y, int w, int h) { - int sx; - int sy; - int sw; - int sh; + int sx = 0; + int sy = 0; + int sw = 0; + int sh = 0; int lx; int ly; @@ -895,10 +895,10 @@ void FScreenGetResistanceRect( Bool FScreenIsRectangleOnScreen(fscreen_scr_arg *arg, fscreen_scr_t screen, rectangle *rec) { - int sx; - int sy; - int sw; - int sh; + int sx = 0; + int sy = 0; + int sw = 0; + int sh = 0; FScreenGetScrRect(arg, screen, &sx, &sy, &sw, &sh); -- 2.30.2
From 31b4637b705a1ff567b9846a77dd284e29b069ef Mon Sep 17 00:00:00 2001 From: Dominik Vogt <dominik.v...@gmx.de> Date: Sat, 20 Nov 2021 00:32:44 +0100 Subject: [PATCH 2/6] Remove obsolete option "-blackout". --- doc/fvwm3_manpage_source.adoc | 7 ------- fvwm/fvwm3.c | 7 ------- 2 files changed, 14 deletions(-) diff --git a/doc/fvwm3_manpage_source.adoc b/doc/fvwm3_manpage_source.adoc index e9642463..8509b27f 100644 --- a/doc/fvwm3_manpage_source.adoc +++ b/doc/fvwm3_manpage_source.adoc @@ -4,7 +4,6 @@ _config-file_] [*-r*] [*-s* [_screen_num_]] [*-V*] [*-C* _visual-class_ | *-I* _visual-id_] [*-l* _colors_ [*-L*] [*-A*] [*-S*] [*-P*]] [*-D*] [*-h*] [*-i* _client-id_] [*-F* _state-file_] [*--debug-stack-ring*] -[*-blackout*] == DESCRIPTION @@ -234,12 +233,6 @@ default, when fvwm does not need a color any more it frees this color so that a new color can be used. This option may speed up image loading and save a few bits of memory. -*-blackout*:: - -This option is provided for backward compatibility only. Blacking out -the screen during startup is not necessary (and doesn't work) anymore. -This option will be removed in the future. - *--debug-stack-ring*:: Enables stack ring debugging. This option is only intended for internal diff --git a/fvwm/fvwm3.c b/fvwm/fvwm3.c index 90acfe13..7f4db058 100644 --- a/fvwm/fvwm3.c +++ b/fvwm/fvwm3.c @@ -1931,13 +1931,6 @@ int main(int argc, char **argv) usage(1); exit(0); } - else if (strcmp(argv[i], "-blackout") == 0) - { - /* obsolete option */ - fvwm_debug(__func__, - "The -blackout option is obsolete, it will be " - "removed in 3.0."); - } else if (strcmp(argv[i], "-r") == 0 || strcmp(argv[i], "-replace") == 0 || strcmp(argv[i], "--replace") == 0) -- 2.30.2
From 6d4a0afc69f7ebe7c829025e220b40b43487137f Mon Sep 17 00:00:00 2001 From: Dominik Vogt <dominik.v...@gmx.de> Date: Sat, 20 Nov 2021 00:44:58 +0100 Subject: [PATCH 3/6] Document -v option and alias it to --verbose. --- doc/fvwm3_manpage_source.adoc | 2 +- fvwm/fvwm3.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/fvwm3_manpage_source.adoc b/doc/fvwm3_manpage_source.adoc index 8509b27f..f647dffa 100644 --- a/doc/fvwm3_manpage_source.adoc +++ b/doc/fvwm3_manpage_source.adoc @@ -238,7 +238,7 @@ save a few bits of memory. Enables stack ring debugging. This option is only intended for internal debugging and should only be used by developers. -*-v*:: +*-v* | *--verbose*:: Enables debug logging. Writes in append mode to fvwm log file, which is ~/.fvwm/fvwm3-output.log by default. See ENVIRONMENT section on how to diff --git a/fvwm/fvwm3.c b/fvwm/fvwm3.c index 7f4db058..972c208d 100644 --- a/fvwm/fvwm3.c +++ b/fvwm/fvwm3.c @@ -1246,6 +1246,7 @@ static void usage(int is_verbose) " -r: replace running window manager\n" " -s [screen]: manage a single screen\n" " -S: static palette\n" + " -v: verbose log output\n" " -V: print version information\n" ); fprintf(stderr, "Try 'man %s' for more information.\n", @@ -2043,7 +2044,9 @@ int main(int argc, char **argv) free(Fvwm_SupportInfo); exit(0); } - else if (strcmp(argv[i], "-v") == 0) + else if ( + strcmp(argv[i], "-v") == 0 || + strcmp(argv[i], "--verbose") == 0) { log_set_level(1); log_open(fvwm_userdir); -- 2.30.2
From cd4108f6fa64826c1fee1b3ea301065234065e2a Mon Sep 17 00:00:00 2001 From: Dominik Vogt <dominik.v...@gmx.de> Date: Sat, 20 Nov 2021 00:51:08 +0100 Subject: [PATCH 4/6] Only important options in SYNOPSIS section. --- doc/fvwm3_manpage_source.adoc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/fvwm3_manpage_source.adoc b/doc/fvwm3_manpage_source.adoc index f647dffa..5e05e7c0 100644 --- a/doc/fvwm3_manpage_source.adoc +++ b/doc/fvwm3_manpage_source.adoc @@ -1,9 +1,12 @@ == SYNOPSIS -*fvwm3* [*-c* _config-command_] [*-d* _displayname_] [*-f* -_config-file_] [*-r*] [*-s* [_screen_num_]] [*-V*] [*-C* _visual-class_ -| *-I* _visual-id_] [*-l* _colors_ [*-L*] [*-A*] [*-S*] [*-P*]] [*-D*] -[*-h*] [*-i* _client-id_] [*-F* _state-file_] [*--debug-stack-ring*] +*fvwm3* +[*-c* _config-command_] +[*-d* _displayname_] +[*-f* _config-file_] +[*-s* [_screen_num_]] +[*-v*] +[other options] == DESCRIPTION -- 2.30.2
From 6fb7cceadf58210bb988e23c62998850ee9e9740 Mon Sep 17 00:00:00 2001 From: Dominik Vogt <dominik.v...@gmx.de> Date: Sat, 20 Nov 2021 01:24:04 +0100 Subject: [PATCH 5/6] getpwuid.[ch]: Make expand_path non-const. --- libs/getpwuid.c | 2 +- libs/getpwuid.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/getpwuid.c b/libs/getpwuid.c index daa11f76..09115332 100644 --- a/libs/getpwuid.c +++ b/libs/getpwuid.c @@ -39,7 +39,7 @@ const char return (home); } -const char * +char * expand_path(const char *path) { char *expanded, *name; diff --git a/libs/getpwuid.h b/libs/getpwuid.h index b2aab003..472c1776 100644 --- a/libs/getpwuid.h +++ b/libs/getpwuid.h @@ -20,6 +20,6 @@ #endif const char *find_home_dir(void); -const char *expand_path(const char *); +char *expand_path(const char *); #endif -- 2.30.2
From 145263564544e28a2e5ef4348f73e94ed92d753f Mon Sep 17 00:00:00 2001 From: Dominik Vogt <dominik.v...@gmx.de> Date: Sat, 20 Nov 2021 01:20:51 +0100 Subject: [PATCH 6/6] libs/log.[ch]: Implement stderr logging. * Export log_level as global variable; remove getter and setter. * Fix memory leak in log_open(). * Move FVWM3_LOGFILE_DEFAULT to defaults.h. --- doc/fvwm3_manpage_source.adoc | 6 +++ fvwm/expand.c | 2 +- fvwm/fvwm3.c | 21 +++++++--- libs/defaults.h | 3 ++ libs/log.c | 72 ++++++++++++++++++++++------------- libs/log.h | 6 +-- 6 files changed, 74 insertions(+), 36 deletions(-) diff --git a/doc/fvwm3_manpage_source.adoc b/doc/fvwm3_manpage_source.adoc index 5e05e7c0..d78b5d22 100644 --- a/doc/fvwm3_manpage_source.adoc +++ b/doc/fvwm3_manpage_source.adoc @@ -4,6 +4,7 @@ [*-c* _config-command_] [*-d* _displayname_] [*-f* _config-file_] +[*-o* _logfile_] [*-s* [_screen_num_]] [*-v*] [other options] @@ -81,6 +82,11 @@ Causes fvwm to read _config-file_ instead of _~/.fvwm/config_ as its initialization file. _$FVWM_USERDIR_ can also be used to change location of default user directory _~/.fvwm_. +*-o* _logfile_:: + +Write log messages to _logfile_. If _logfile_ is '-', log to the +console. (Does not turn on logging, see the *-v* option.) + *-h* | *--help*:: A short usage description is printed. diff --git a/fvwm/expand.c b/fvwm/expand.c index 1e8a87d4..3d366bb5 100644 --- a/fvwm/expand.c +++ b/fvwm/expand.c @@ -1140,7 +1140,7 @@ static signed int expand_vars_extended( break; case VAR_DEBUG_LOG_STATE: is_numeric = True; - val = log_get_level(); + val = lib_log_level; break; default: /* unknown variable - try to find it in the environment */ diff --git a/fvwm/fvwm3.c b/fvwm/fvwm3.c index 972c208d..ba76aa98 100644 --- a/fvwm/fvwm3.c +++ b/fvwm/fvwm3.c @@ -1242,6 +1242,7 @@ static void usage(int is_verbose) " -I vis-id: use visual <vis-id>\n" " -l colors: try to use no more than <colors> colors\n" " -L: strict color limit\n" + " -o logfile: output file or '-' for stderr\n" " -P: visual palette\n" " -r: replace running window manager\n" " -s [screen]: manage a single screen\n" @@ -1803,6 +1804,7 @@ int main(int argc, char **argv) fvwm_userdir); } + set_log_file(NULL); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-debug_stack_ring") == 0 || @@ -2044,12 +2046,20 @@ int main(int argc, char **argv) free(Fvwm_SupportInfo); exit(0); } - else if ( - strcmp(argv[i], "-v") == 0 || - strcmp(argv[i], "--verbose") == 0) + else if (strcmp(argv[i], "-v") == 0 || + strcmp(argv[i], "--verbose") == 0) { - log_set_level(1); - log_open(fvwm_userdir); + lib_log_level = 1; + } + else if (strcmp(argv[i], "-o") == 0 || + strcmp(argv[i], "--output-file") == 0) + { + if (++i >= argc) + { + usage(0); + exit(1); + } + set_log_file(argv[i]); } else { @@ -2059,6 +2069,7 @@ int main(int argc, char **argv) exit(1); } } + log_open(fvwm_userdir); InstallSignals(); diff --git a/libs/defaults.h b/libs/defaults.h index 37783968..643b1f24 100644 --- a/libs/defaults.h +++ b/libs/defaults.h @@ -10,6 +10,9 @@ #ifndef FVWMLIB_DEFAULTS_H #define FVWMLIB_DEFAULTS_H +/*** logging ***/ +#define FVWM3_LOGFILE_DEFAULT "fvwm3-output.log" + /*** event handling ***/ #define CLOCK_SKEW_MS 30000 /* ms */ diff --git a/libs/log.c b/libs/log.c index 2f33712c..2f5406a4 100644 --- a/libs/log.c +++ b/libs/log.c @@ -31,47 +31,65 @@ #include "getpwuid.h" #include "log.h" +static char *log_file_name; static FILE *log_file; -static int log_level; +int lib_log_level = 0; -static void log_vwrite(const char *, const char *, va_list); - -/* Set log level. */ void -log_set_level(int ll) +set_log_file(char *name) { - log_level = ll; -} + if (log_file_name != NULL) + { + free(log_file_name); + log_file_name = NULL; + } + if (name != NULL) + { + log_file_name = fxstrdup(name); + } -/* Get log level. */ -int log_get_level(void) -{ - return log_level; + return; } /* Open logging to file. */ void log_open(const char *fvwm_userdir) { - char *path, *logfile_env; - - xasprintf(&path, "%s/%s", fvwm_userdir, FVWM3_LOGFILE_DEFAULT); + char *path, *file_name; - logfile_env = getenv("FVWM3_LOGFILE"); - if (logfile_env != NULL) { - const char *expanded_path; - - expanded_path = expand_path(logfile_env); + if (lib_log_level == 0) + return; + if ( + log_file_name != NULL && + log_file_name[0] == '-' && log_file_name[1] == 0) + { + log_file = stderr; + return; + } + file_name = log_file_name; + if (file_name == NULL) + file_name = getenv("FVWM3_LOGFILE"); + if (file_name != NULL) + { + char *expanded_path; + + expanded_path = expand_path(file_name); if (expanded_path[0] == '/') - path = fxstrdup(expanded_path); + { + path = expanded_path; + } else + { xasprintf(&path, "%s/%s", fvwm_userdir, expanded_path); - free((char *)expanded_path); + free((char *)expanded_path); + } + } + else + { + xasprintf(&path, "%s/%s", fvwm_userdir, FVWM3_LOGFILE_DEFAULT); } - if (log_level == 0) - return; log_close(); log_file = fopen(path, "a"); @@ -89,13 +107,13 @@ log_open(const char *fvwm_userdir) void log_toggle(const char *fvwm_userdir) { - if (log_level == 0) { - log_level = 1; + if (lib_log_level == 0) { + lib_log_level = 1; log_open(fvwm_userdir); fvwm_debug(NULL, "log opened (because of SIGUSR2)"); } else { fvwm_debug(NULL, "log closed (because of SIGUSR2)"); - log_level = 0; + lib_log_level = 0; log_close(); } } @@ -104,7 +122,7 @@ log_toggle(const char *fvwm_userdir) void log_close(void) { - if (log_file != NULL) + if (log_file != NULL && log_file != stderr) fclose(log_file); log_file = NULL; } diff --git a/libs/log.h b/libs/log.h index 2bd85c09..93753105 100644 --- a/libs/log.h +++ b/libs/log.h @@ -2,10 +2,10 @@ #define FVWMLIB_LOG_H #define printflike(a, b) __attribute__ ((format (printf, a, b))) -#define FVWM3_LOGFILE_DEFAULT "fvwm3-output.log" -void log_set_level(int); -int log_get_level(void); +extern int lib_log_level; + +void set_log_file(char *name); void log_open(const char *); void log_toggle(const char *); void log_close(void); -- 2.30.2