[CRIU] [PATCH] util: Add "/bin" to PATH when spawning helpers

Pavel Emelyanov xemul at parallels.com
Fri Feb 7 08:52:05 PST 2014


We call tar, ip, iptables, etc. when restoring container.
The problem is that these stuff is called from inside new
mount namespace after pivot_root(). But the execvp uses
PATH variable inherited from the host system, which may
not reflect real binaries layout.

Add "/bin" to path as temporary workaround.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 util.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/util.c b/util.c
index 4304a91..e9845ef 100644
--- a/util.c
+++ b/util.c
@@ -481,6 +481,47 @@ int run_scripts(char *action)
 		ret__;						\
 	})
 
+static int fixup_env(void)
+{
+	char *ep, *nep;
+	int len;
+
+	/*
+	 * FIXME
+	 *
+	 * We sometimes call other tools inside namespace
+	 * we restore. Host system may not have PATH properly
+	 * reflecting where the tools are in other namespaces.
+	 *
+	 * E.g. when restoring Centos6 container from FC20
+	 * host we fail to find /bin/tar, as in FC20 /bin is
+	 * not in PATH.
+	 *
+	 * It's not cool at all, things we think we call might
+	 * not coincide with what is really called. Proper fix
+	 * will come a bit later.
+	 */
+
+	ep = getenv("PATH");
+	if (!ep)
+		return 0;
+
+	len = strlen(ep);
+	nep = xmalloc(len + sizeof("/bin:"));
+	if (!nep)
+		return -1;
+
+	sprintf(nep, "/bin:%s", ep);
+	if (setenv("PATH", nep, 1)) {
+		pr_perror("Failed to override PATH");
+		xfree(nep);
+		return -1;
+	}
+
+	xfree(nep);
+	return 0;
+}
+
 /*
  * If "in" is negative, stdin will be closed.
  * If "out" or "err" are negative, a log file descriptor will be used.
@@ -503,6 +544,9 @@ int cr_system(int in, int out, int err, char *cmd, char *const argv[])
 		pr_perror("fork() failed");
 		goto out;
 	} else if (pid == 0) {
+		if (fixup_env())
+			goto out_chld;
+
 		if (out < 0)
 			out = log_get_fd();
 		if (err < 0)
-- 
1.7.6.5


More information about the CRIU mailing list