diff --git a/src/common/dir.c b/src/common/dir.c index 10b95763..75adb072 100644 --- a/src/common/dir.c +++ b/src/common/dir.c @@ -103,8 +103,7 @@ char *find_dir(struct ctx *ctx) } } /* no directory was found */ - ctx->buf[0] = '.'; - ctx->buf[1] = '\0'; + ctx->buf[0] = '\0'; return ctx->buf; } diff --git a/src/common/log.c b/src/common/log.c index e3385b1f..c67e8e1e 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -23,7 +23,7 @@ void warn(const char *err, ...) { va_list params; fprintf(stderr, LABWC_COLOR_RED); - fprintf(stderr, "[labwc] warning: "); + fprintf(stderr, "[labwc] "); va_start(params, err); vfprintf(stderr, err, params); va_end(params); diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 5ce5ed56..835bea19 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -260,12 +260,11 @@ static void post_processing(void) set_title_height(); } -static void rcxml_path(char *buf, size_t len, const char *filename) +static void rcxml_path(char *buf, size_t len) { - if (filename) - snprintf(buf, len, "%s", filename); - else - snprintf(buf, len, "%s/rc.xml", config_dir()); + if (!strlen(config_dir())) + return; + snprintf(buf, len, "%s/rc.xml", config_dir()); } void rcxml_read(const char *filename) @@ -274,7 +273,7 @@ void rcxml_read(const char *filename) char *line = NULL; size_t len = 0; struct buf b; - char rcxml[4096]; + char rcxml[4096] = { 0 }; rcxml_init(); wl_list_init(&rc.keybinds); @@ -283,13 +282,20 @@ void rcxml_read(const char *filename) * Reading file into buffer before parsing makes it easier to write * unit tests. */ - rcxml_path(rcxml, sizeof(rcxml), filename); - info("reading config file (%s)", rcxml); + if (filename) + snprintf(rcxml, sizeof(rcxml), "%s", filename); + else + rcxml_path(rcxml, sizeof(rcxml)); + if (rcxml[0] == '\0') { + warn("cannot find rc.xml config file"); + goto no_config; + } stream = fopen(rcxml, "r"); if (!stream) { warn("cannot read (%s)", rcxml); - goto out; + goto no_config; } + info("reading config file (%s)", rcxml); buf_init(&b); while (getline(&line, &len, stream) != -1) { char *p = strrchr(line, '\n'); @@ -301,7 +307,7 @@ void rcxml_read(const char *filename) fclose(stream); rcxml_parse_xml(&b); free(b.buf); -out: +no_config: post_processing(); } diff --git a/src/theme/theme.c b/src/theme/theme.c index 4abb3621..5942d0c6 100644 --- a/src/theme/theme.c +++ b/src/theme/theme.c @@ -118,19 +118,22 @@ void theme_builtin(void) void theme_read(const char *theme_name) { - FILE *stream; + FILE *stream = NULL; char *line = NULL; size_t len = 0; char themerc[4096]; - snprintf(themerc, sizeof(themerc), "%s/themerc", theme_dir(theme_name)); - info("reading themerc (%s)", themerc); - stream = fopen(themerc, "r"); + if (strlen(theme_dir(theme_name))) { + snprintf(themerc, sizeof(themerc), "%s/themerc", + theme_dir(theme_name)); + stream = fopen(themerc, "r"); + } if (!stream) { - warn("cannot read (%s) - load built-in theme", themerc); + warn("cannot find theme (%s), using built-in", theme_name); theme_builtin(); return; } + info("reading themerc (%s)", themerc); while (getline(&line, &len, stream) != -1) { char *p = strrchr(line, '\n'); if (p)