From e4988217c65d4194c704e0a6e1026d68c85946a6 Mon Sep 17 00:00:00 2001 From: Allison Lortie Date: Tue, 14 Jun 2016 16:09:46 -0400 Subject: [PATCH 2/2] 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 --- src/authutil.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/authutil.c b/src/authutil.c index 7950e27..c03dae4 100644 --- a/src/authutil.c +++ b/src/authutil.c @@ -67,7 +67,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; @@ -82,7 +82,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]) { @@ -107,7 +112,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) { @@ -119,8 +128,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); } -- 2.8.1