[CRIU] [PATCH 1/3] crtools: allow to use --inherit-fd on dump to mark inhereted descriptors

Andrey Vagin avagin at openvz.org
Thu Nov 26 01:32:45 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 crtools.c       |  4 ----
 files.c         | 14 +++++++++-----
 include/files.h |  1 +
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/crtools.c b/crtools.c
index 123ad06..0a4b8b5 100644
--- a/crtools.c
+++ b/crtools.c
@@ -597,10 +597,6 @@ int main(int argc, char *argv[], char *envp[])
 		return 1;
 
 	if (!list_empty(&opts.inherit_fds)) {
-		if (strcmp(argv[optind], "restore")) {
-			pr_err("--inherit-fd is restore-only option\n");
-			return 1;
-		}
 		/* now that log file is set up, print inherit fd list */
 		inherit_fd_log();
 	}
diff --git a/files.c b/files.c
index da6a5ae..c0f7586 100644
--- a/files.c
+++ b/files.c
@@ -1333,6 +1333,8 @@ static int inherit_fd_reused(struct inherit_fd *inh)
 {
 	struct stat sbuf;
 
+	if (inh->inh_fd < 0)
+		return 0;
 	if (fstat(inh->inh_fd, &sbuf) == -1) {
 		if (errno == EBADF) {
 			pr_debug("Inherit fd %s -> %d has been closed\n",
@@ -1373,10 +1375,10 @@ int inherit_fd_parse(char *optarg)
 		dbg = 1;
 	}
 	if (cp) {
-		n = sscanf(cp, "[%d]:", &fd);
+		sscanf(cp, "[%d]:", &fd);
 		cp = strchr(optarg, ':');
 	}
-	if (n != 1 || fd < 0 || !cp || !cp[1]) {
+	if (!cp || !cp[1]) {
 		pr_err("Invalid inherit fd argument: %s\n", optarg);
 		return -1;
 	}
@@ -1402,9 +1404,9 @@ int inherit_fd_parse(char *optarg)
 int inherit_fd_add(int fd, char *key)
 {
 	struct inherit_fd *inh;
-	struct stat sbuf;
+	struct stat sbuf = {};
 
-	if (fstat(fd, &sbuf) == -1) {
+	if (fd >= 0 && fstat(fd, &sbuf) == -1) {
 		pr_perror("Can't fstat inherit fd %d", fd);
 		return -1;
 	}
@@ -1440,7 +1442,7 @@ void inherit_fd_log(void)
 /*
  * Look up the inherit fd list by a file identifier.
  */
-static int inherit_fd_lookup_id(char *id)
+int inherit_fd_lookup_id(char *id)
 {
 	int ret;
 	struct inherit_fd *inh;
@@ -1450,6 +1452,8 @@ static int inherit_fd_lookup_id(char *id)
 		if (!strcmp(inh->inh_id, id)) {
 			if (!inherit_fd_reused(inh)) {
 				ret = inh->inh_fd;
+				if (ret < 0)
+					ret = 0;
 				pr_debug("Found id %s (fd %d) in inherit fd list\n",
 					id, ret);
 			}
diff --git a/include/files.h b/include/files.h
index db7e108..c974c2e 100644
--- a/include/files.h
+++ b/include/files.h
@@ -176,5 +176,6 @@ extern int inherit_fd_resolve_clash(int fd);
 extern int inherit_fd_fini(void);
 
 extern bool inherited_fd(struct file_desc *, int *fdp);
+extern int inherit_fd_lookup_id(char *id);
 
 #endif /* __CR_FILES_H__ */
-- 
2.4.3



More information about the CRIU mailing list