From 3458210c1ce348a48d21571090665d5fb545d329 Mon Sep 17 00:00:00 2001 From: akarl10 Date: Mon, 30 Jan 2023 09:38:05 +0100 Subject: [PATCH] [chansrv-fuse] Add %d and %D as path replacement variables %d is the numeric display number %D is the DISPLAY environment variable this enables the concurrent use of fuse in multiple sessions of the same user --- sesman/chansrv/chansrv_fuse.c | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index a2ea8d23..4c9f65e2 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -2795,10 +2795,14 @@ static unsigned int format_user_info(char *dest, unsigned int len, { char uidstr[64]; char username[64]; + char display[64]; + char displaynum[64]; const struct info_string_tag map[] = { {'u', uidstr}, {'U', username}, + {'d', displaynum}, + {'D', display}, INFO_STRING_END_OF_LIST }; @@ -2810,6 +2814,42 @@ static unsigned int format_user_info(char *dest, unsigned int len, g_strncpy(username, uidstr, sizeof(username) - 1); } + if (getenv("DISPLAY") == NULL) + { + /* if environment variable is not set, set it to empty string */ + g_strncpy(display, "", 1); + g_strncpy(displaynum, "-1", 3); + } + else + { + const char *start = display; + const char *end = NULL; + g_strncpy(display, getenv("DISPLAY"), sizeof(display) - 1); + while (*start != '\0' && *start != ':') + { + start++; + } + if (*start == ':') + { + start++; + } + else + { + start = display; + } + + end = start; + while (*end != '\0' && *end != '.') + { + end++; + } + if (end - start > (sizeof(displaynum) - 1)) + { + end = start + sizeof(displaynum) - 1; + } + g_strncpy(displaynum, start, end - start); + } + return g_format_info_string(dest, len, format, map); }