summary refs log tree commit diff
path: root/calmwm.c
diff options
context:
space:
mode:
authorokan <okan>2018-02-09 19:54:54 +0000
committerokan <okan>2018-02-09 19:54:54 +0000
commit1a5f80bd0b9865994ef02244da597044dd99a309 (patch)
tree9e56d668478dfabd1dfe699360ebcaef08c8eab5 /calmwm.c
parentf3211427c16b755db20bc71ce4074e9fb9aae8af (diff)
downloadcwm-1a5f80bd0b9865994ef02244da597044dd99a309.tar.gz
cwm-1a5f80bd0b9865994ef02244da597044dd99a309.tar.xz
cwm-1a5f80bd0b9865994ef02244da597044dd99a309.zip
Clean up conf_file/homedir and conf_init() bits.
Diffstat (limited to 'calmwm.c')
-rw-r--r--calmwm.c41
1 files changed, 8 insertions, 33 deletions
diff --git a/calmwm.c b/calmwm.c
index 9deb9a3..875b0ca 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -28,7 +28,6 @@
 #include <limits.h>
 #include <locale.h>
 #include <poll.h>
-#include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -54,23 +53,24 @@ static int	x_wmerrorhandler(Display *, XErrorEvent *);
 int
 main(int argc, char **argv)
 {
-	const char	*conf_file = NULL;
-	char		*conf_path, *display_name = NULL;
+	char		*display_name = NULL;
 	char		*fallback;
 	int		 ch, xfd;
 	struct pollfd	 pfd[1];
-	struct passwd	*pw;
 
 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
 		warnx("no locale support");
 	mbtowc(NULL, NULL, MB_CUR_MAX);
 
+	conf_init(&Conf);
+
 	fallback = u_argv(argv);
 	Conf.wm_argv = u_argv(argv);
 	while ((ch = getopt(argc, argv, "c:d:v")) != -1) {
 		switch (ch) {
 		case 'c':
-			conf_file = optarg;
+			free(Conf.conf_file);
+			Conf.conf_file = xstrdup(optarg);
 			break;
 		case 'd':
 			display_name = optarg;
@@ -90,32 +90,8 @@ main(int argc, char **argv)
 	if (signal(SIGHUP, sighdlr) == SIG_ERR)
 		err(1, "signal");
 
-	Conf.homedir = getenv("HOME");
-	if ((Conf.homedir == NULL) || (Conf.homedir[0] == '\0')) {
-		pw = getpwuid(getuid());
-		if (pw != NULL && pw->pw_dir != NULL && *pw->pw_dir != '\0')
-			Conf.homedir = pw->pw_dir;
-		else
-			Conf.homedir = "/";
-	}
-
-	if (conf_file == NULL)
-		xasprintf(&conf_path, "%s/%s", Conf.homedir, CONFFILE);
-	else
-		conf_path = xstrdup(conf_file);
-
-	if (access(conf_path, R_OK) != 0) {
-		if (conf_file != NULL)
-			warn("%s", conf_file);
-		free(conf_path);
-		conf_path = NULL;
-	}
-
-	conf_init(&Conf);
-
-	if (conf_path && (parse_config(conf_path, &Conf) == -1))
-		warnx("config file %s has errors", conf_path);
-	free(conf_path);
+	if (parse_config(Conf.conf_file, &Conf) == -1)
+		warnx("error parsing config file");
 
 	xfd = x_init(display_name);
 	cwm_status = CWM_RUNNING;
@@ -136,7 +112,7 @@ main(int argc, char **argv)
 	x_teardown();
 	if (cwm_status == CWM_EXEC_WM) {
 		u_exec(Conf.wm_argv);
-		warnx("'%s' failed to start, restarting fallback", Conf.wm_argv);
+		warnx("'%s' failed to start, starting fallback", Conf.wm_argv);
 		u_exec(fallback);
 	}
 
@@ -198,7 +174,6 @@ static int
 x_wmerrorhandler(Display *dpy, XErrorEvent *e)
 {
 	errx(1, "root window unavailable - perhaps another wm is running?");
-
 	return(0);
 }