]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
build: Move interactive flag from jail
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 16:36:45 +0000 (16:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 16:38:01 +0000 (16:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/build.c
src/libpakfire/include/pakfire/build.h
src/libpakfire/include/pakfire/jail.h
src/libpakfire/jail.c
src/scripts/pakfire.in
tests/libpakfire/jail.c

index 7f4c9abb18eccde73f5dcbbaad6c3e3725a19fce..b2b8e19055b7daf05e2b64cf0c925df685f676c4 100644 (file)
@@ -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) {
index 51c6e2039083168765adaf91a6876386e3b6d9fd..4883003c24421c03ef2c95f29c2badd7b432bf49 100644 (file)
@@ -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;
index b7f109e12116d50e3ca97eea8a77accb040996d9..726d32d3ecb47504879fa64f4314a04aebaa2a57 100644 (file)
@@ -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,
index e284c83b81f00a19731f5f9df30c46d2f1d4428b..d96782118adf38ee3a55ee9ae0478e3bfa1e3e21 100644 (file)
@@ -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,
index e022ff4f5f9e91822755944c640cc541d184ac52..0351284afefb0319a6cbf6ec2a7440327d50052c 100644 (file)
@@ -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) {
index c298f6a05abc18298413f676184510651f8ba30e..363cb29e34b67cf6c0e44638ca8fb9a5cc011e33 100644 (file)
@@ -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:
index d3b0505a0a14566a8bc4c3bb88b5575b091bbe44..59431d50ddaac00bf7d731d2a4fb332d91124ec6 100644 (file)
@@ -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: