[Pkg-wmaker-commits] [wmbutton] 15/25: wmbutton: fail early on missing config
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Sun Jul 16 23:38:09 UTC 2017
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch upstream
in repository wmbutton.
commit 157298eb8ebc7a2d94c5a2f4cb53176b1514226d
Author: Weland Treebark <weland at blinkenshell.org>
Date: Wed May 28 21:34:14 2014 +0300
wmbutton: fail early on missing config
wmbutton will happily start and display what otherwise looks like a
functioning display even if none of the possible configuration files
exist. However, the application promptly exits as soon as it has to show
a tooltip. This isn't nice. It looks like a crash to an unsuspecting
user. Terminal output is shown, of course, leading to a decently quick
diagnostic, but the fail isn't early enough to be useable.
The trivial fix is to check if the local configuration file (specified
as a command line argument or defaulting to ~/.wmbutton) or the global
configuration file can be open. If neither can be open, we bail out
early.
This *still* has the problem of only really being functional in a
terminal. A graphical error box would definitely be preferable and is a
possible improvement.
Signed-off-by: Weland Treebark <weland at blinkenshell.org>
---
wmb_libs.c | 17 +++++++++++++++++
wmbutton.c | 8 ++++++++
wmbutton.h | 1 +
3 files changed, 26 insertions(+)
diff --git a/wmb_libs.c b/wmb_libs.c
index 55802ff..e778743 100644
--- a/wmb_libs.c
+++ b/wmb_libs.c
@@ -192,6 +192,23 @@ void RunAppN(int app)
/***********************************************************************/
/***********************************************************************
+ * canOpenFile(const char *path)
+ *
+ * Check if the file at a given path can be opened.
+ ***********************************************************************/
+int canOpenFile(const char *path)
+{
+ FILE *fp;
+
+ if ((fp = fopen(path, "r")) == NULL)
+ return 0;
+ else {
+ fclose(fp);
+ return 1;
+ }
+}
+
+/***********************************************************************
* Parse(int app)
*
* Parses the file 'configfile' for command to execute.
diff --git a/wmbutton.c b/wmbutton.c
index 7b061b0..6d4dd26 100644
--- a/wmbutton.c
+++ b/wmbutton.c
@@ -111,6 +111,14 @@ int main(int argc, char **argv)
/* Parse Command Line Arguments */
parseargs(argc, argv);
+ /* Catch fire if no configuration file exists */
+ if (!canOpenFile(Config.configfile)) {
+ if(!canOpenFile(CONFIGGLOBAL)) {
+ err_mess(FAILCONF, Config.configfile);
+ return (1);
+ }
+ }
+
/* Open Display */
if ((display = XOpenDisplay(Config.Display_str)) == NULL)
err_mess(FAILDISP, Config.Display_str);
diff --git a/wmbutton.h b/wmbutton.h
index b653e7d..4cd3a68 100644
--- a/wmbutton.h
+++ b/wmbutton.h
@@ -84,6 +84,7 @@ void parseargs(int argc, char **argv);
char *readln(FILE *fp); /* read line from file, return pointer to it */
void err_mess(int err, char *str); /* Error Handling Routine */
void show_usage(void); /* show usage message to stderr */
+int canOpenFile(const char *path);
int flush_expose(Window w);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbutton.git
More information about the Pkg-wmaker-commits
mailing list