about summary refs log tree commit diff
path: root/kbfunc.c
diff options
context:
space:
mode:
authorokan <okan>2008-04-05 21:09:19 +0000
committerokan <okan>2008-04-05 21:09:19 +0000
commitcb2cc70c3f757ca57addd3d7fba49353380ed5b2 (patch)
tree5688af5ad8cd76fbc65c8d30c83f44dcccfd0411 /kbfunc.c
parentef0859de2063bf735afd142613f2ea3212e6558f (diff)
downloadcwm-cb2cc70c3f757ca57addd3d7fba49353380ed5b2.tar.gz
cwm-cb2cc70c3f757ca57addd3d7fba49353380ed5b2.tar.xz
cwm-cb2cc70c3f757ca57addd3d7fba49353380ed5b2.zip
- use $PATH before _PATH_DEFPATH, from Tim van der Molen
- plug leak, noticed by oga

feedback and ok oga@
Diffstat (limited to 'kbfunc.c')
-rw-r--r--kbfunc.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/kbfunc.c b/kbfunc.c
index 8192cae..781a06a 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -264,7 +264,7 @@ void
 kbfunc_exec(struct client_ctx *scratch, void *arg)
 {
 #define NPATHS 256
-	char **ap, *paths[NPATHS], *path, tpath[MAXPATHLEN];
+	char **ap, *paths[NPATHS], *path, *pathcpy, tpath[MAXPATHLEN];
 	int l, i, j, ngroups;
 	gid_t mygroups[NGROUPS_MAX];
 	uid_t ruid, euid, suid;
@@ -294,14 +294,18 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
 		err(1, "getresuid failure");
 
 	TAILQ_INIT(&menuq);
-	/* just use default path until we have config to set this */
-	path = xstrdup(_PATH_DEFPATH);
+
+	if ((path = getenv("PATH")) == NULL)
+		path = _PATH_DEFPATH;
+	pathcpy = path = xstrdup(path);
+
 	for (ap = paths; ap < &paths[NPATHS - 1] &&
-	    (*ap = strsep(&path, ":")) != NULL;) {
+	    (*ap = strsep(&pathcpy, ":")) != NULL;) {
 		if (**ap != '\0')
 			ap++;
 	}
 	*ap = NULL;
+	xfree(path);
 	for (i = 0; i < NPATHS && paths[i] != NULL; i++) {
 		if ((dirp = opendir(paths[i])) == NULL)
 			continue;
@@ -367,7 +371,6 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
 		TAILQ_REMOVE(&menuq, mi, entry);
 		xfree(mi);
 	}
-	xfree(path);
 }
 
 void