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
--- 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);
}