summaryrefslogtreecommitdiff
path: root/app/cwm
diff options
context:
space:
mode:
authorOkan Demirmen <okan@cvs.openbsd.org>2018-02-09 19:54:55 +0000
committerOkan Demirmen <okan@cvs.openbsd.org>2018-02-09 19:54:55 +0000
commit9ade9f192471298846c34133eea2bfe051a22bf5 (patch)
treeeb61c48f57173f8919267b26a63840a19de0ea0d /app/cwm
parent25f0ae676c8b801888d521c45ad53df1835ac08a (diff)
Clean up conf_file/homedir and conf_init() bits.
Diffstat (limited to 'app/cwm')
-rw-r--r--app/cwm/calmwm.c43
-rw-r--r--app/cwm/calmwm.h8
-rw-r--r--app/cwm/conf.c27
3 files changed, 31 insertions, 47 deletions
diff --git a/app/cwm/calmwm.c b/app/cwm/calmwm.c
index 6804030a8..101bdbf66 100644
--- a/app/cwm/calmwm.c
+++ b/app/cwm/calmwm.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: calmwm.c,v 1.108 2018/02/04 22:56:26 okan Exp $
+ * $OpenBSD: calmwm.c,v 1.109 2018/02/09 19:54:54 okan Exp $
*/
#include <sys/types.h>
@@ -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);
}
diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h
index a4933471b..fb1fa3379 100644
--- a/app/cwm/calmwm.h
+++ b/app/cwm/calmwm.h
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: calmwm.h,v 1.356 2018/02/04 22:56:26 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.357 2018/02/09 19:54:54 okan Exp $
*/
#ifndef _CALMWM_H_
@@ -45,8 +45,6 @@
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
#endif
-#define CONFFILE ".cwmrc"
-
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
#define MENUMASK (MOUSEMASK | ButtonMotionMask | KeyPressMask | \
@@ -308,10 +306,10 @@ struct conf {
Cursor cursor[CF_NITEMS];
int xrandr;
int xrandr_event_base;
- char *homedir;
+ char *conf_file;
char *known_hosts;
char *wm_argv;
- u_int32_t debug;
+ int debug;
};
/* MWM hints */
diff --git a/app/cwm/conf.c b/app/cwm/conf.c
index af76f6d5a..138f0962d 100644
--- a/app/cwm/conf.c
+++ b/app/cwm/conf.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: conf.c,v 1.239 2018/02/02 13:27:25 okan Exp $
+ * $OpenBSD: conf.c,v 1.240 2018/02/09 19:54:54 okan Exp $
*/
#include <sys/types.h>
@@ -25,6 +25,7 @@
#include <err.h>
#include <errno.h>
#include <limits.h>
+#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -248,6 +249,8 @@ mouse_binds[] = {
void
conf_init(struct conf *c)
{
+ const char *home;
+ struct passwd *pw;
unsigned int i;
c->stickygroups = 0;
@@ -258,11 +261,11 @@ conf_init(struct conf *c)
c->nameqlen = 5;
TAILQ_INIT(&c->ignoreq);
- TAILQ_INIT(&c->cmdq);
- TAILQ_INIT(&c->wmq);
- TAILQ_INIT(&c->keybindq);
TAILQ_INIT(&c->autogroupq);
+ TAILQ_INIT(&c->keybindq);
TAILQ_INIT(&c->mousebindq);
+ TAILQ_INIT(&c->cmdq);
+ TAILQ_INIT(&c->wmq);
for (i = 0; i < nitems(key_binds); i++)
conf_bind_key(c, key_binds[i].key, key_binds[i].func);
@@ -275,13 +278,21 @@ conf_init(struct conf *c)
conf_cmd_add(c, "lock", "xlock");
conf_cmd_add(c, "term", "xterm");
-
conf_wm_add(c, "cwm", "cwm");
- xasprintf(&c->known_hosts, "%s/%s", c->homedir, ".ssh/known_hosts");
-
c->font = xstrdup("sans-serif:pixelsize=14:bold");
c->wmname = xstrdup("CWM");
+
+ home = getenv("HOME");
+ if ((home == NULL) || (*home == '\0')) {
+ pw = getpwuid(getuid());
+ if (pw != NULL && pw->pw_dir != NULL && *pw->pw_dir != '\0')
+ home = pw->pw_dir;
+ else
+ home = "/";
+ }
+ xasprintf(&c->conf_file, "%s/%s", home, ".cwmrc");
+ xasprintf(&c->known_hosts, "%s/%s", home, ".ssh/known_hosts");
}
void
@@ -327,6 +338,7 @@ conf_clear(struct conf *c)
for (i = 0; i < CWM_COLOR_NITEMS; i++)
free(c->color[i]);
+ free(c->conf_file);
free(c->known_hosts);
free(c->font);
free(c->wmname);
@@ -703,7 +715,6 @@ static char *ewmhints[] = {
"_NET_WM_STATE_SKIP_TASKBAR",
"_CWM_WM_STATE_FREEZE",
};
-
void
conf_atoms(void)
{