[lxc-devel] [lxc/master] tools: lxc-unshare: replace write_id_mapping() to the same function in conf.c

2xsec on Github lxc-bot at linuxcontainers.org
Sat Jul 7 10:56:43 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 393 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180707/f437d8f9/attachment.bin>
-------------- next part --------------
From 23ccbdeda820819729d379f3c82b873a733ac0c3 Mon Sep 17 00:00:00 2001
From: 2xsec <dh48.jeong at samsung.com>
Date: Sat, 7 Jul 2018 19:52:11 +0900
Subject: [PATCH] tools: lxc-unshare: replace write_id_mapping() to the same
 function in conf.c

Signed-off-by: 2xsec <dh48.jeong at samsung.com>
---
 src/lxc/tools/lxc_unshare.c | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c
index 669186ec1..85b9d4c02 100644
--- a/src/lxc/tools/lxc_unshare.c
+++ b/src/lxc/tools/lxc_unshare.c
@@ -41,6 +41,7 @@
 
 #include "arguments.h"
 #include "caps.h"
+#include "conf.h"
 #include "namespace.h"
 #include "utils.h"
 
@@ -220,28 +221,6 @@ static int do_start(void *arg)
 	return 1;
 }
 
-static int write_id_mapping(pid_t pid, const char *buf, size_t buf_size)
-{
-	char path[MAXPATHLEN];
-	int fd, ret;
-
-	ret = snprintf(path, MAXPATHLEN, "/proc/%d/uid_map", pid);
-	if (ret < 0 || ret >= MAXPATHLEN)
-		return -E2BIG;
-
-	fd = open(path, O_WRONLY);
-	if (fd < 0)
-		return -1;
-
-	errno = 0;
-	ret = lxc_write_nointr(fd, buf, buf_size);
-	close(fd);
-	if (ret < 0 || (size_t)ret != buf_size)
-		return -1;
-
-	return 0;
-}
-
 int main(int argc, char *argv[])
 {
 	char **args;
@@ -357,7 +336,7 @@ int main(int argc, char *argv[])
 			exit(EXIT_FAILURE);
 		}
 
-		ret = write_id_mapping(pid, umap, strlen(umap));
+		ret = write_id_mapping(ID_TYPE_UID, pid, umap, strlen(umap));
 		if (ret < 0) {
 			close(start_arg.wait_fd);
 			fprintf(stderr, "uid mapping failed\n");


More information about the lxc-devel mailing list