"command",
"environ",
"bind",
- "interactive",
"logging_callback",
"nice",
"return_output",
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
goto ERROR;
}
- // Interactive?
- if (interactive)
- flags |= PAKFIRE_JAIL_INTERACTIVE;
-
// Create jail
r = pakfire_jail_create(&jail, self->pakfire, flags);
if (r) {
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;
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,
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,
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;
}
// 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;
}
// 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)
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);
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];
"/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) {
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)
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:
// 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: