diff options
author | okan | 2012-12-17 23:03:41 +0000 |
---|---|---|
committer | okan | 2012-12-17 23:03:41 +0000 |
commit | b5092167190004004d01ad01dd180ded079a0457 (patch) | |
tree | 214b6d5a085da7574ded5c0f27ea3b5f7a69fef9 /calmwm.c | |
parent | 068d256bb7f3ff3381885ac9668d70d69271ac37 (diff) | |
download | cwm-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
Diffstat (limited to 'calmwm.c')
-rw-r--r-- | calmwm.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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)); |