[lxc-devel] [lxc/master] criu: replace tmpnam() with mkstemp()

brauner on Github lxc-bot at linuxcontainers.org
Thu Jul 28 22:55:23 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 352 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160728/09a4616d/attachment.bin>
-------------- next part --------------
From 9b1e2e6e2c17e8babf033f782abd704d649c5ac9 Mon Sep 17 00:00:00 2001
From: Christian Brauner <cbrauner at suse.de>
Date: Fri, 29 Jul 2016 00:53:53 +0200
Subject: [PATCH] criu: replace tmpnam() with mkstemp()

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

diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 69d25cf..bf9a87a 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -603,11 +603,13 @@ static bool restore_net_info(struct lxc_container *c)
 static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_opts *opts, char *criu_version)
 {
 	pid_t pid;
-	char pidfile[L_tmpnam];
 	struct lxc_handler *handler;
-	int status, pipes[2] = {-1, -1};
+	int fd, status;
+	int pipes[2] = {-1, -1};
+	char pidfile[] = "criu_restore_XXXXXX";
 
-	if (!tmpnam(pidfile))
+	fd = mkstemp(pidfile);
+	if (fd < 0)
 		goto out;
 
 	handler = lxc_init(c->name, c->lxc_conf, c->config_path);
@@ -756,11 +758,12 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
 				goto out_fini_handler;
 			} else {
 				int ret;
-				FILE *f = fopen(pidfile, "r");
+				FILE *f = fdopen(fd, "r");
 				if (!f) {
 					SYSERROR("couldn't read restore's init pidfile %s\n", pidfile);
 					goto out_fini_handler;
 				}
+				fd = -1;
 
 				ret = fscanf(f, "%d", (int*) &handler->pid);
 				fclose(f);
@@ -818,6 +821,9 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
 		close(status_pipe);
 	}
 
+	if (fd > 0)
+		close(fd);
+
 	exit(1);
 }
 


More information about the lxc-devel mailing list