From: Michael Tremer Date: Tue, 2 Aug 2022 14:44:38 +0000 (+0000) Subject: jail: Execute command X-Git-Tag: 0.9.28~631 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3498aebf86aab2dde2503984f853f7046dbb0c5;p=pakfire.git jail: Execute command Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 16539d121..457baed56 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -586,7 +586,23 @@ static int pakfire_jail_child(struct pakfire_jail* jail, const char* argv[], int if (r) return r; - return 0; + // exec() command + r = execvpe(argv[0], (char**)argv, jail->env); + if (r < 0) + ERROR(jail->pakfire, "Could not execve(): %m\n"); + + // Translate errno into regular exit code + switch (errno) { + case ENOENT: + r = 127; + break; + + default: + r = 1; + } + + // We should not get here + return r; } // Run a command in the jail @@ -595,6 +611,12 @@ int pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[]) { int status = 0; int r; + // Check if argv is valid + if (!argv || !argv[0]) { + errno = EINVAL; + return -1; + } + DEBUG(jail->pakfire, "Executing jail...\n"); /* diff --git a/tests/libpakfire/jail.c b/tests/libpakfire/jail.c index ec8987393..ec7a6b65b 100644 --- a/tests/libpakfire/jail.c +++ b/tests/libpakfire/jail.c @@ -87,7 +87,7 @@ static int test_exec(const struct test* t) { ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, 0)); // Try to execute something - ASSERT_SUCCESS(pakfire_jail_exec(jail, argv)); + ASSERT(pakfire_jail_exec(jail, argv) == 127); // Destroy it ASSERT_NULL(pakfire_jail_unref(jail));