abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 3e9a3fdf4d7a6ba309bf8fed2975f6447455f60e
parent 21dd6ad6b745bfa8381c50a90809a5caea9308dd
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed,  6 Jan 2016 14:37:56 +0100

Make socket directory location configurable via config.def.h

Introduce $ABDUCO_SOCKET_DIR environment variable to set a
default location.

Diffstat:
abduco.1 | 16++++++++++------
abduco.c | 34++++++++++++++--------------------
config.def.h | 13+++++++++++++
3 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/abduco.1 b/abduco.1 @@ -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. diff --git a/abduco.c b/abduco.c @@ -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; diff --git a/config.def.h b/config.def.h @@ -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 }, +};