changeset 30681:0064a1eb28e2

chg: respect XDG_RUNTIME_DIR $XDG_RUNTIME_DIR [1] is a better place for user daemons. Let's use it and fallback to $TMPDIR. After this patch, chg will try socket paths in the following order: 1. $CHGSOCKNAME 2. $XDG_RUNTIME_DIR/chg/server 3. ${TMPDIR:-tmp}/chg$UID/server [1]: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
author Jun Wu <quark@fb.com>
date Mon, 26 Dec 2016 00:02:42 +0000
parents 4677df6b449a
children 95325386cd1a
files contrib/chg/chg.c
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/chg.c	Sun Dec 25 23:49:54 2016 +0000
+++ b/contrib/chg/chg.c	Mon Dec 26 00:02:42 2016 +0000
@@ -130,11 +130,18 @@
 static void getdefaultsockdir(char sockdir[], size_t size)
 {
 	/* by default, put socket file in secure directory
+	 * (${XDG_RUNTIME_DIR}/chg, or /${TMPDIR:-tmp}/chg$UID)
 	 * (permission of socket file may be ignored on some Unices) */
-	const char *tmpdir = getenv("TMPDIR");
-	if (!tmpdir)
-		tmpdir = "/tmp";
-	int r = snprintf(sockdir, size, "%s/chg%d", tmpdir, geteuid());
+	const char *runtimedir = getenv("XDG_RUNTIME_DIR");
+	int r;
+	if (runtimedir) {
+		r = snprintf(sockdir, size, "%s/chg", runtimedir);
+	} else {
+		const char *tmpdir = getenv("TMPDIR");
+		if (!tmpdir)
+			tmpdir = "/tmp";
+		r = snprintf(sockdir, size, "%s/chg%d", tmpdir, geteuid());
+	}
 	if (r < 0 || (size_t)r >= size)
 		abortmsg("too long TMPDIR (r = %d)", r);
 }