From: Michael Tremer Date: Tue, 16 Aug 2022 16:36:45 +0000 (+0000) Subject: build: Move interactive flag from jail X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db4f234fd9a3dc1c875d4e9563c8f57b073f1078;p=people%2Fstevee%2Fpakfire.git build: Move interactive flag from jail Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 7f4c9abb..b2b8e190 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -809,7 +809,6 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* "command", "environ", "bind", - "interactive", "logging_callback", "nice", "return_output", @@ -826,13 +825,12 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* PyObject* command = NULL; PyObject* environ = NULL; PyObject* bind = NULL; - int interactive = 0; PyObject* logging_callback = NULL; int nice = 0; int return_output = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOpOip", kwlist, &command, &environ, - &bind, &interactive, &logging_callback, &nice, &return_output)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOOip", kwlist, &command, &environ, + &bind, &logging_callback, &nice, &return_output)) return NULL; // Check if command is a list @@ -873,10 +871,6 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* goto ERROR; } - // Interactive? - if (interactive) - flags |= PAKFIRE_JAIL_INTERACTIVE; - // Create jail r = pakfire_jail_create(&jail, self->pakfire, flags); if (r) { diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 51c6e203..4883003c 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -1324,7 +1324,7 @@ PAKFIRE_EXPORT int pakfire_shell(struct pakfire* pakfire, const char** packages) int r; // Create a new build environment - r = pakfire_build_create(&build, pakfire, NULL, 0); + r = pakfire_build_create(&build, pakfire, NULL, PAKFIRE_BUILD_INTERACTIVE); if (r) { ERROR(pakfire, "Could not create build: %m\n"); goto ERROR; diff --git a/src/libpakfire/include/pakfire/build.h b/src/libpakfire/include/pakfire/build.h index b7f109e1..726d32d3 100644 --- a/src/libpakfire/include/pakfire/build.h +++ b/src/libpakfire/include/pakfire/build.h @@ -26,8 +26,9 @@ struct pakfire_build; enum pakfire_build_flags { - PAKFIRE_BUILD_DISABLE_SNAPSHOT = (1 << 0), - PAKFIRE_BUILD_DISABLE_CCACHE = (1 << 1), + PAKFIRE_BUILD_INTERACTIVE = (1 << 0), + PAKFIRE_BUILD_DISABLE_SNAPSHOT = (1 << 1), + PAKFIRE_BUILD_DISABLE_CCACHE = (1 << 2), }; int pakfire_build_create(struct pakfire_build** build, diff --git a/src/libpakfire/include/pakfire/jail.h b/src/libpakfire/include/pakfire/jail.h index e284c83b..d9678211 100644 --- a/src/libpakfire/include/pakfire/jail.h +++ b/src/libpakfire/include/pakfire/jail.h @@ -25,9 +25,8 @@ struct pakfire_jail; -enum { +enum pakfire_jail_flags { PAKFIRE_JAIL_NONE = 0, - PAKFIRE_JAIL_INTERACTIVE = (1 << 0), }; typedef int (*pakfire_jail_log_callback)(struct pakfire* pakfire, void* data, diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index e022ff4f..0351284a 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -246,13 +246,6 @@ PAKFIRE_EXPORT int pakfire_jail_create(struct pakfire_jail** jail, goto ERROR; } - // Setup interactive stuff - if (j->flags & PAKFIRE_JAIL_INTERACTIVE) { - r = pakfire_jail_setup_interactive_env(j); - if (r) - goto ERROR; - } - // Done *jail = j; return 0; @@ -1322,7 +1315,8 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe } // Run a command in the jail -static int __pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[]) { +static int __pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[], + const int interactive) { int exit = -1; int r; @@ -1353,7 +1347,7 @@ static int __pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[]) { } // Create pipes to communicate with child process if we are not running interactively - if (!pakfire_jail_has_flag(jail, PAKFIRE_JAIL_INTERACTIVE)) { + if (interactive) { // stdout r = pakfire_jail_setup_pipe(jail, &ctx.pipes.stdout, 0); if (r) @@ -1500,7 +1494,7 @@ PAKFIRE_EXPORT int pakfire_jail_exec(struct pakfire_jail* jail, pakfire_jail_set_log_callback(jail, pakfire_jail_capture_stdout, output); // Run exec() - r = __pakfire_jail_exec(jail, argv); + r = __pakfire_jail_exec(jail, argv, 0); // Restore log callback pakfire_jail_set_log_callback(jail, log_callback, log_data); @@ -1508,6 +1502,18 @@ PAKFIRE_EXPORT int pakfire_jail_exec(struct pakfire_jail* jail, return r; } +static int pakfire_jail_exec_interactive( + struct pakfire_jail* jail, const char* argv[]) { + int r; + + // Setup interactive stuff + r = pakfire_jail_setup_interactive_env(jail); + if (r) + return r; + + return __pakfire_jail_exec(jail, argv, 1); +} + PAKFIRE_EXPORT int pakfire_jail_exec_script(struct pakfire_jail* jail, const char* script, const size_t size, const char* args[], char** output) { char path[PATH_MAX]; @@ -1636,15 +1642,8 @@ int pakfire_jail_shell(struct pakfire_jail* jail) { "/bin/bash", "--login", NULL, }; - // Check if this operation is possible - if (!pakfire_jail_has_flag(jail, PAKFIRE_JAIL_INTERACTIVE)) { - ERROR(jail->pakfire, "You cannot run a shell in a non-interactive jail\n"); - errno = ENOTSUP; - return 1; - } - // Execute /bin/bash - return pakfire_jail_exec(jail, argv, NULL); + return pakfire_jail_exec_interactive(jail, argv); } int pakfire_jail_ldconfig(struct pakfire* pakfire) { diff --git a/src/scripts/pakfire.in b/src/scripts/pakfire.in index c298f6a0..363cb29e 100644 --- a/src/scripts/pakfire.in +++ b/src/scripts/pakfire.in @@ -76,8 +76,6 @@ class Cli(object): help=_("Executes a command in the pakfire environment (useful for development)")) execute.add_argument("--bind", action="append", default=[], dest="binds", help=_("Bind-mounts the given directory")) - execute.add_argument("--non-interactive", action="store_false", dest="interactive", - help=_("Run in non-interactive mode")) execute.add_argument("command", nargs=argparse.REMAINDER) execute.set_defaults(func=self._execute) @@ -316,7 +314,7 @@ class Cli(object): try: return p.execute(args.command, bind=args.binds, - interactive=args.interactive, logging_callback=logging_callback) + logging_callback=logging_callback) # Exit program with the command's exit code except pakfire.errors.CommandExecutionError as e: diff --git a/tests/libpakfire/jail.c b/tests/libpakfire/jail.c index d3b0505a..59431d50 100644 --- a/tests/libpakfire/jail.c +++ b/tests/libpakfire/jail.c @@ -50,12 +50,6 @@ static int test_create(const struct test* t) { // Destroy it ASSERT_NULL(pakfire_jail_unref(jail)); - // Create an interactive jail - ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, PAKFIRE_JAIL_INTERACTIVE)); - - // Destroy it again - ASSERT_NULL(pakfire_jail_unref(jail)); - return EXIT_SUCCESS; FAIL: