From b484311c929a1b64966d89da92fafce7263006e1 Mon Sep 17 00:00:00 2001 From: Allison Lortie Date: Tue, 14 Jun 2016 16:09:46 -0400 Subject: 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 --- src/authutil.c | 18 +++++++++++++----- 1 file 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); } -- cgit v1.2.3