Make socket directory location configurable via config.def.h

Introduce $ABDUCO_SOCKET_DIR environment variable to set a
default location.
This commit is contained in:
Marc André Tanner 2016-01-06 14:37:56 +01:00
parent 21dd6ad6b7
commit 3e9a3fdf4d
3 changed files with 36 additions and 25 deletions

View File

@ -56,13 +56,17 @@ is examined, if it is not set
.BR dvtm(1)
is executed.
By default all session related information is stored in
All session related information is stored in the following directories (first
to succeed is used):
.RS
.nf
.PP
.B $ABDUCO_SOCKET_DIR/abduco
.B $HOME/.abduco
with
.BR $TMPDIR/abduco/$USER
as a fallback and
.BR /tmp/abduco/$USER
as a last resort.
.B $TMPDIR/abduco/$USER
.B /tmp/abduco/$USER
.fi
.RE
However if a given session name represents either a relative or absolute path
it is used unmodified.

View File

@ -276,29 +276,23 @@ static bool create_socket_dir(struct sockaddr_un *sockaddr) {
size_t maxlen = sizeof(sockaddr->sun_path);
uid_t uid = getuid();
struct passwd *pw = getpwuid(uid);
char *home = getenv("HOME");
if ((!home || !home[0]) && pw)
home = pw->pw_dir;
struct {
char *dir;
bool personal; /* whether it is a per user directory */
} dirs[] = {
{ home, true },
{ getenv("TMPDIR"), false },
{ "/tmp", false },
};
for (unsigned int i = 0; i < countof(dirs); i++) {
for (unsigned int i = 0; i < countof(socket_dirs); i++) {
struct stat sb;
char *dir = dirs[i].dir;
bool ispersonal = dirs[i].personal;
if (!dir)
struct Dir *dir = &socket_dirs[i];
bool ishome = false;
if (dir->env) {
dir->path = getenv(dir->env);
ishome = !strcmp(dir->env, "HOME");
if (ishome && (!dir->path || !dir->path[0]) && pw)
dir->path = pw->pw_dir;
}
if (!dir->path || !dir->path[0])
continue;
if (!xsnprintf(sockaddr->sun_path, maxlen, "%s/%s%s/", dir, dir == home ? "." : "", server.name))
if (!xsnprintf(sockaddr->sun_path, maxlen, "%s/%s%s/", dir->path, ishome ? "." : "", server.name))
continue;
mode_t mask = umask(0);
int r = mkdir(sockaddr->sun_path, ispersonal ? S_IRWXU : S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
int r = mkdir(sockaddr->sun_path, dir->personal ? S_IRWXU : S_IRWXU|S_IRWXG|S_IRWXO|S_ISVTX);
umask(mask);
if (r != 0 && errno != EEXIST)
continue;
@ -310,7 +304,7 @@ static bool create_socket_dir(struct sockaddr_un *sockaddr) {
}
size_t dirlen = strlen(sockaddr->sun_path);
if (!ispersonal) {
if (!dir->personal) {
/* create subdirectory only accessible to user */
if (pw && !xsnprintf(sockaddr->sun_path+dirlen, maxlen-dirlen, "%s/", pw->pw_name))
continue;

View File

@ -1,2 +1,15 @@
static char KEY_DETACH = CTRL('\\');
static char KEY_REDRAW = 0;
/* Where to place the "abduco" directory storing all session socket files.
* The first directory to succeed is used. */
static struct Dir {
char *path; /* fixed (absolute) path to a directory */
char *env; /* environment variable to use if (set) */
bool personal; /* if false a user owned sub directory will be created */
} socket_dirs[] = {
{ .env = "ABDUCO_SOCKET_DIR", false },
{ .env = "HOME", true },
{ .env = "TMPDIR", false },
{ .path = "/tmp", false },
};