summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllison Lortie <desrt@desrt.ca>2016-06-14 16:09:46 -0400
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-03-24 14:18:09 -0700
commitb484311c929a1b64966d89da92fafce7263006e1 (patch)
tree5a677684a311a92289b1bbe77d9b8f4cd0251943
parent48ed5e04b5a8ba64dcfeea090cf3a32d3087b749 (diff)
authutil: support $XDG_RUNTIME_DIR/ICEauthority
If we find that $XDG_RUNTIME_DIR is set (and $ICEAUTHORITY is not), then the ICEauthority file is stored in the XDG_RUNTIME_DIR instead of the home directory, and without a leading dot. https://bugs.freedesktop.org/show_bug.cgi?id=49173 Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--src/authutil.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/authutil.c b/src/authutil.c
index e2e5979..86a716b 100644
--- a/src/authutil.c
+++ b/src/authutil.c
@@ -66,7 +66,7 @@ static Status write_counted_string (FILE *file, unsigned short count, const char
char *
IceAuthFileName (void)
{
- static char slashDotICEauthority[] = "/.ICEauthority";
+ const char *ICEauthority_name = ".ICEauthority";
char *name;
static char *buf;
static size_t bsize;
@@ -81,7 +81,12 @@ IceAuthFileName (void)
if ((name = getenv ("ICEAUTHORITY")))
return (name);
- name = getenv ("HOME");
+ /* If it's in the XDG_RUNTIME_DIR, don't use a dotfile */
+ if ((name = getenv ("XDG_RUNTIME_DIR")))
+ ICEauthority_name++;
+
+ if (!name || !name[0])
+ name = getenv ("HOME");
if (!name || !name[0])
{
@@ -106,7 +111,11 @@ IceAuthFileName (void)
return (NULL);
}
- size = strlen (name) + strlen (&slashDotICEauthority[1]) + 2;
+ /* Special case for "/". We will add our own '/' later. */
+ if (name[1] == '\0')
+ name++;
+
+ size = strlen (name) + 1 + strlen (ICEauthority_name) + 1;
if (size > bsize)
{
@@ -120,8 +129,7 @@ IceAuthFileName (void)
bsize = size;
}
- snprintf (buf, bsize, "%s%s", name,
- slashDotICEauthority + (name[1] == '\0' ? 1 : 0));
+ snprintf (buf, bsize, "%s/%s", name, ICEauthority_name);
return (buf);
}