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@blinkenshell.org>
This commit is contained in:
parent
145662ff35
commit
9f5ea8c8d7
|
@ -191,6 +191,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)
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue