abduco

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

commit 4c3e2c8c70cf42f15c922a4038bea63c1ab3dfa2
parent 0681dc8dafd9e5b6b988894e6ed882ad105bd3d2
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 15 May 2018 14:27:44 +0200

Expose current session name as $ABDUCO_SESSION

The supervised command can use it to determine in which session it
is running. It is not necessarily identical to the file name of the
underlying socket as stored in the file system.

Diffstat:
abduco.1 | 2++
abduco.c | 13++++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/abduco.1 b/abduco.1 @@ -142,6 +142,8 @@ is not specified, the environment variable is examined, if it is not set .Xr dvtm 1 is executed. +.It Ev ABDUCO_SESSION +The current session name available to the supervised command. .El .Pp See the diff --git a/abduco.c b/abduco.c @@ -353,6 +353,9 @@ static bool create_socket_dir(struct sockaddr_un *sockaddr) { static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) { const size_t maxlen = sizeof(sockaddr->sun_path); + const char *session_name = NULL; + char buf[maxlen]; + if (name[0] == '/') { if (strlen(name) >= maxlen) { errno = ENAMETOOLONG; @@ -360,7 +363,7 @@ static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) { } strncpy(sockaddr->sun_path, name, maxlen); } else if (name[0] == '.' && (name[1] == '.' || name[1] == '/')) { - char buf[maxlen], *cwd = getcwd(buf, sizeof buf); + char *cwd = getcwd(buf, sizeof buf); if (!cwd) return false; if (!xsnprintf(sockaddr->sun_path, maxlen, "%s/%s", cwd, name)) @@ -372,9 +375,17 @@ static bool set_socket_name(struct sockaddr_un *sockaddr, const char *name) { errno = ENAMETOOLONG; return false; } + session_name = name; strncat(sockaddr->sun_path, name, maxlen - strlen(sockaddr->sun_path) - 1); strncat(sockaddr->sun_path, server.host, maxlen - strlen(sockaddr->sun_path) - 1); } + + if (!session_name) { + strncpy(buf, sockaddr->sun_path, sizeof buf); + session_name = basename(buf); + } + setenv("ABDUCO_SESSION", session_name, 1); + return true; }