From: Michael Tremer Date: Thu, 14 Jan 2021 13:45:32 +0000 (+0000) Subject: libpakfire: execute: Call chroot() and personality() only when necessary X-Git-Tag: 0.9.28~1285^2~855 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ea5571cadcdca0fdae7c81f5db0ab65545a6da0;p=pakfire.git libpakfire: execute: Call chroot() and personality() only when necessary Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/execute.c b/src/libpakfire/execute.c index 03db62fd5..4ce6805ea 100644 --- a/src/libpakfire/execute.c +++ b/src/libpakfire/execute.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -57,25 +58,29 @@ static int pakfire_execute_fork(void* data) { for (unsigned int i = 0; env->envp[i]; i++) DEBUG(pakfire, " env : %s\n", env->envp[i]); - // Move / - int r = chroot(root); - if (r) { - ERROR(pakfire, "chroot() to %s failed: %s\n", root, strerror(errno)); + // Change root (unless root is /) + if (strcmp(root, "/") != 0) { + int r = chroot(root); + if (r) { + ERROR(pakfire, "chroot() to %s failed: %s\n", root, strerror(errno)); - return 1; + return 1; + } } // Set personality unsigned long persona = pakfire_arch_personality(arch); - r = personality(persona); - if (r < 0) { - ERROR(pakfire, "Could not set personality (%x)\n", (unsigned int)persona); + if (persona) { + int r = personality(persona); + if (r < 0) { + ERROR(pakfire, "Could not set personality (%x)\n", (unsigned int)persona); - return 1; + return 1; + } } // exec() command - r = execve(env->argv[0], (char**)env->argv, env->envp); + int r = execve(env->argv[0], (char**)env->argv, env->envp); if (r < 0) { ERROR(pakfire, "Could not execve(): %s\n", strerror(errno)); }