mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
pull user home directory via getenv or getpwuid and stash it so we don't
need to do this everytime; with Tiago Cunha
This commit is contained in:
parent
fe44d1dfce
commit
75f65f399e
11
calmwm.c
11
calmwm.c
|
@ -26,6 +26,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -48,6 +49,7 @@ struct client_ctx_q Clientq = TAILQ_HEAD_INITIALIZER(Clientq);
|
||||||
|
|
||||||
int HasRandr, Randr_ev;
|
int HasRandr, Randr_ev;
|
||||||
struct conf Conf;
|
struct conf Conf;
|
||||||
|
char *homedir;
|
||||||
|
|
||||||
static void sigchld_cb(int);
|
static void sigchld_cb(int);
|
||||||
static void dpy_init(const char *);
|
static void dpy_init(const char *);
|
||||||
|
@ -62,6 +64,7 @@ main(int argc, char **argv)
|
||||||
const char *conf_file = NULL;
|
const char *conf_file = NULL;
|
||||||
char *display_name = NULL;
|
char *display_name = NULL;
|
||||||
int ch;
|
int ch;
|
||||||
|
struct passwd *pw;
|
||||||
|
|
||||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
warnx("no locale support");
|
warnx("no locale support");
|
||||||
|
@ -86,6 +89,14 @@ main(int argc, char **argv)
|
||||||
if (signal(SIGCHLD, sigchld_cb) == SIG_ERR)
|
if (signal(SIGCHLD, sigchld_cb) == SIG_ERR)
|
||||||
err(1, "signal");
|
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);
|
dpy_init(display_name);
|
||||||
|
|
||||||
bzero(&Conf, sizeof(Conf));
|
bzero(&Conf, sizeof(Conf));
|
||||||
|
|
1
calmwm.h
1
calmwm.h
|
@ -519,6 +519,7 @@ extern Cursor Cursor_resize;
|
||||||
extern struct screen_ctx_q Screenq;
|
extern struct screen_ctx_q Screenq;
|
||||||
extern struct client_ctx_q Clientq;
|
extern struct client_ctx_q Clientq;
|
||||||
extern struct conf Conf;
|
extern struct conf Conf;
|
||||||
|
extern char *homedir;
|
||||||
|
|
||||||
extern int HasRandr, Randr_ev;
|
extern int HasRandr, Randr_ev;
|
||||||
|
|
||||||
|
|
6
conf.c
6
conf.c
|
@ -243,18 +243,14 @@ void
|
||||||
conf_setup(struct conf *c, const char *conf_file)
|
conf_setup(struct conf *c, const char *conf_file)
|
||||||
{
|
{
|
||||||
char conf_path[MAXPATHLEN];
|
char conf_path[MAXPATHLEN];
|
||||||
char *home;
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int parse = 0;
|
int parse = 0;
|
||||||
|
|
||||||
conf_init(c);
|
conf_init(c);
|
||||||
|
|
||||||
if (conf_file == NULL) {
|
if (conf_file == NULL) {
|
||||||
if ((home = getenv("HOME")) == NULL)
|
|
||||||
errx(1, "No HOME directory.");
|
|
||||||
|
|
||||||
(void)snprintf(conf_path, sizeof(conf_path), "%s/%s",
|
(void)snprintf(conf_path, sizeof(conf_path), "%s/%s",
|
||||||
home, CONFFILE);
|
homedir, CONFFILE);
|
||||||
|
|
||||||
if (stat(conf_path, &sb) == 0 && (sb.st_mode & S_IFREG))
|
if (stat(conf_path, &sb) == 0 && (sb.st_mode & S_IFREG))
|
||||||
parse = 1;
|
parse = 1;
|
||||||
|
|
7
kbfunc.c
7
kbfunc.c
|
@ -324,16 +324,13 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
|
||||||
struct menu *mi;
|
struct menu *mi;
|
||||||
struct menu_q menuq;
|
struct menu_q menuq;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *buf, *lbuf, *p, *home;
|
char *buf, *lbuf, *p;
|
||||||
char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN];
|
char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN];
|
||||||
char cmd[256];
|
char cmd[256];
|
||||||
int l;
|
int l;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if ((home = getenv("HOME")) == NULL)
|
l = snprintf(filename, sizeof(filename), "%s/%s", homedir, KNOWN_HOSTS);
|
||||||
return;
|
|
||||||
|
|
||||||
l = snprintf(filename, sizeof(filename), "%s/%s", home, KNOWN_HOSTS);
|
|
||||||
if (l == -1 || l >= sizeof(filename))
|
if (l == -1 || l >= sizeof(filename))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user