[lxc-devel] [lxc/master] tools: use correct runtime path for lxc-ls

brauner on Github lxc-bot at linuxcontainers.org
Fri Aug 12 23:02:40 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 508 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160812/768ab079/attachment.bin>
-------------- next part --------------
From 2263d59596829eca3c9987a2673f2ce3cd077173 Mon Sep 17 00:00:00 2001
From: Christian Brauner <cbrauner at suse.de>
Date: Sat, 13 Aug 2016 00:56:33 +0200
Subject: [PATCH] tools: use correct runtime path for lxc-ls

So far we've simply been using RUNTIME_PATH for the privileged and unprivileged
case. We should actually use XDG_RUNTIME_DIR for the unprivileged case.

Signed-off-by: Christian Brauner <cbrauner at suse.de>
---
 src/lxc/tools/lxc_ls.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/lxc/tools/lxc_ls.c b/src/lxc/tools/lxc_ls.c
index e2a4c34..0575277 100644
--- a/src/lxc/tools/lxc_ls.c
+++ b/src/lxc/tools/lxc_ls.c
@@ -986,25 +986,40 @@ static int ls_get_wrapper(void *wrap)
 static int ls_remove_lock(const char *path, const char *name,
 		char **lockpath, size_t *len_lockpath, bool recalc)
 {
+	int ret = -1;
+	char *rundir;
+
+	/* lockfile will be:
+	 * "/run" + "/lxc/lock/$lxcpath/$lxcname + '\0' if root
+	 * or
+	 * $XDG_RUNTIME_DIR + "/lxc/lock/$lxcpath/$lxcname + '\0' if non-root
+	 */
+	rundir = get_rundir();
+	if (!rundir)
+		goto out;
+
 	/* Avoid doing unnecessary work if we can. */
 	if (recalc) {
-		size_t newlen = strlen(path) + strlen(name) + strlen(RUNTIME_PATH) + /* / + lxc + / + lock + / + / = */ 11 + 1;
+		size_t newlen = strlen(path) + strlen(name) + strlen(rundir) + /* / + lxc + / + lock + / + / = */ 11 + 1;
 		if (newlen > *len_lockpath) {
 			char *tmp = realloc(*lockpath, newlen * 2);
 			if (!tmp)
-				return -1;
+				goto out;
 			*lockpath = tmp;
 			*len_lockpath = newlen * 2;
 		}
 	}
 
-	int check = snprintf(*lockpath, *len_lockpath, "%s/lxc/lock/%s/%s", RUNTIME_PATH, path, name);
+	int check = snprintf(*lockpath, *len_lockpath, "%s/lxc/lock/%s/%s", rundir, path, name);
 	if (check < 0 || (size_t)check >= *len_lockpath)
-		return -1;
+		goto out;
 
 	lxc_rmdir_onedev(*lockpath, NULL);
+	ret = 0;
 
-	return 0;
+out:
+	free(rundir);
+	return ret;
 }
 
 static int ls_send_str(int fd, const char *buf)


More information about the lxc-devel mailing list