[lxc-devel] [lxc/master] lxc-copy: do not use mkostemp and dprintf

brauner on Github lxc-bot at linuxcontainers.org
Fri Jul 22 20:01:43 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 912 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160722/a795062c/attachment.bin>
-------------- next part --------------
From a8e279fd537184f2300d2b94822bf2a7c63e208b Mon Sep 17 00:00:00 2001
From: Christian Brauner <cbrauner at suse.de>
Date: Fri, 22 Jul 2016 21:59:24 +0200
Subject: [PATCH] lxc-copy: do not use mkostemp and dprintf

Fixes android builds:

DSBINDIR=\"/data/lxc/lxc/sbin\"      -I/build/libcap/libcap/include/ -Wall -Werror -MT lxc_copy.o -MD -MP -MF $depbase.Tpo -c -o lxc_copy.o lxc_copy.c &&\
	mv -f $depbase.Tpo $depbase.Po
lxc_copy.c: In function 'mount_tmpfs':
lxc_copy.c:834:2: error: implicit declaration of function 'mkostemp' [-Werror=implicit-function-declaration]
  fd = mkostemp(premount, O_CLOEXEC);
  ^
lxc_copy.c:841:2: error: implicit declaration of function 'dprintf' [-Werror=implicit-function-declaration]
  ret = dprintf(fd, "#! /bin/sh\n"
  ^

Signed-off-by: Christian Brauner <cbrauner at suse.de>
---
 src/lxc/lxc_copy.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/lxc/lxc_copy.c b/src/lxc/lxc_copy.c
index cb73471..69de7d5 100644
--- a/src/lxc/lxc_copy.c
+++ b/src/lxc/lxc_copy.c
@@ -805,6 +805,7 @@ static char *mount_tmpfs(const char *oldname, const char *newname,
 	int ret, fd;
 	size_t len;
 	char *premount = NULL;
+	FILE *fp;
 
 	if (arg->tmpfs && arg->keepdata) {
 		fprintf(stderr, "%s\n", "A container can only be placed on a "
@@ -831,21 +832,31 @@ static char *mount_tmpfs(const char *oldname, const char *newname,
 	if (ret < 0 || (size_t)ret >= len)
 		goto err_free;
 
-	fd = mkostemp(premount, O_CLOEXEC);
+	fd = mkstemp(premount);
 	if (fd < 0)
 		goto err_free;
 
+	if (fcntl(fd, F_SETFD, FD_CLOEXEC)) {
+		SYSERROR("Failed to set close-on-exec on file descriptor.");
+		goto err_close;
+	}
+
 	if (chmod(premount, 0755) < 0)
 		goto err_close;
 
-	ret = dprintf(fd, "#! /bin/sh\n"
+	fp = fdopen(fd, "r+");
+	if (!fp)
+		goto err_close;
+	fd = -1;
+
+	ret = fprintf(fp, "#! /bin/sh\n"
 			  "mount -n -t tmpfs -o mode=0755 none %s/%s\n",
 		      path, newname);
 	if (ret < 0)
 		goto err_close;
 
 	if (!arg->keepname) {
-		ret = dprintf(fd, "mkdir -p %s/%s/delta0/etc\n"
+		ret = fprintf(fp, "mkdir -p %s/%s/delta0/etc\n"
 				  "echo %s > %s/%s/delta0/etc/hostname\n",
 			      path, newname, newname, path, newname);
 		if (ret < 0)
@@ -856,7 +867,10 @@ static char *mount_tmpfs(const char *oldname, const char *newname,
 	return premount;
 
 err_close:
-	close(fd);
+	if (fd > 0)
+		close(fd);
+	else
+		fclose(fp);
 err_free:
 	free(premount);
 	return NULL;


More information about the lxc-devel mailing list