aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokan2012-12-17 23:03:41 +0000
committerokan2012-12-17 23:03:41 +0000
commitb5092167190004004d01ad01dd180ded079a0457 (patch)
tree214b6d5a085da7574ded5c0f27ea3b5f7a69fef9
parent068d256bb7f3ff3381885ac9668d70d69271ac37 (diff)
downloadcwm-b5092167190004004d01ad01dd180ded079a0457.tar.gz
pull user home directory via getenv or getpwuid and stash it so we don't
need to do this everytime; with Tiago Cunha
-rw-r--r--calmwm.c13
-rw-r--r--calmwm.h3
-rw-r--r--conf.c8
-rw-r--r--kbfunc.c9
4 files changed, 19 insertions, 14 deletions
diff --git a/calmwm.c b/calmwm.c
index 3a7393d..18da2a7 100644
--- a/calmwm.c
+++ b/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.70 2012/12/17 02:28:45 okan Exp $
+ * $OpenBSD: calmwm.c,v 1.71 2012/12/17 23:03:41 okan Exp $
*/
#include <sys/param.h>
@@ -26,6 +26,7 @@
#include <errno.h>
#include <getopt.h>
#include <locale.h>
+#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -48,6 +49,7 @@ struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
int HasRandr, Randr_ev;
struct conf Conf;
+char *homedir;
static void sigchld_cb(int);
static void dpy_init(const char *);
@@ -62,6 +64,7 @@ main(int argc, char **argv)
const char *conf_file = NULL;
char *display_name = NULL;
int ch;
+ struct passwd *pw;
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
warnx("no locale support");
@@ -86,6 +89,14 @@ main(int argc, char **argv)
if (signal(SIGCHLD, sigchld_cb) == SIG_ERR)
err(1, "signal");
+ if ((homedir = getenv("HOME")) == NULL || *homedir == '\0') {
+ pw = getpwuid(getuid());
+ if (pw != NULL && pw->pw_dir != NULL && *pw->pw_dir != '\0')
+ homedir = pw->pw_dir;
+ else
+ homedir = "/";
+ }
+
dpy_init(display_name);
bzero(&Conf, sizeof(Conf));
diff --git a/calmwm.h b/calmwm.h
index 05e56a3..6ee87be 100644
--- a/calmwm.h
+++ b/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.171 2012/12/17 18:35:26 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.172 2012/12/17 23:03:41 okan Exp $
*/
#ifndef _CALMWM_H_
@@ -519,6 +519,7 @@ extern Cursor Cursor_resize;
extern struct screen_ctx_q Screenq;
extern struct client_ctx_q Clientq;
extern struct conf Conf;
+extern char *homedir;
extern int HasRandr, Randr_ev;
diff --git a/conf.c b/conf.c
index 2b7fded..b31a32c 100644
--- a/conf.c
+++ b/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.112 2012/12/17 02:53:29 okan Exp $
+ * $OpenBSD: conf.c,v 1.113 2012/12/17 23:03:41 okan Exp $
*/
#include <sys/param.h>
@@ -243,18 +243,14 @@ void
conf_setup(struct conf *c, const char *conf_file)
{
char conf_path[MAXPATHLEN];
- char *home;
struct stat sb;
int parse = 0;
conf_init(c);
if (conf_file == NULL) {
- if ((home = getenv("HOME")) == NULL)
- errx(1, "No HOME directory.");
-
(void)snprintf(conf_path, sizeof(conf_path), "%s/%s",
- home, CONFFILE);
+ homedir, CONFFILE);
if (stat(conf_path, &sb) == 0 && (sb.st_mode & S_IFREG))
parse = 1;
diff --git a/kbfunc.c b/kbfunc.c
index f58982b..a134999 100644
--- a/kbfunc.c
+++ b/kbfunc.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: kbfunc.c,v 1.69 2012/12/17 14:32:39 okan Exp $
+ * $OpenBSD: kbfunc.c,v 1.70 2012/12/17 23:03:41 okan Exp $
*/
#include <sys/param.h>
@@ -324,16 +324,13 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
struct menu *mi;
struct menu_q menuq;
FILE *fp;
- char *buf, *lbuf, *p, *home;
+ char *buf, *lbuf, *p;
char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN];
char cmd[256];
int l;
size_t len;
- if ((home = getenv("HOME")) == NULL)
- return;
-
- l = snprintf(filename, sizeof(filename), "%s/%s", home, KNOWN_HOSTS);
+ l = snprintf(filename, sizeof(filename), "%s/%s", homedir, KNOWN_HOSTS);
if (l == -1 || l >= sizeof(filename))
return;