#include <pakfire/build.h>
#include <pakfire/pakfire.h>
+#define MAX_ARGS 128
#define MAX_PACKAGES 128
struct config {
int flags;
+ // Arguments
+ const char* argv[MAX_ARGS + 1];
+ unsigned int argc;
+
// Packages
const char* packages[MAX_PACKAGES + 1];
unsigned int num_packages;
config->packages[config->num_packages++] = arg;
break;
+ case ARGP_KEY_ARG:
+ if (config->argc >= MAX_ARGS)
+ return -ENOBUFS;
+
+ config->argv[config->argc++] = arg;
+ break;
+
default:
return ARGP_ERR_UNKNOWN;
}
struct config config = {
.flags = PAKFIRE_BUILD_INTERACTIVE,
+ .argv = {},
+ .argc = 0,
.packages = {},
.num_packages = 0,
};
goto ERROR;
}
- // Run shell
- r = pakfire_build_shell(build);
+ // Run the command
+ r = pakfire_build_shell(build, (config.argc) ? config.argv : NULL);
ERROR:
if (build)
{ "repo", cli_repo, -1, -1, 0 },
{ "repolist", cli_repolist, 0, 0, 0 },
{ "requires", cli_requires, 1, -1, 0 },
- { "shell", cli_shell, 0, 0, 0 },
+ { "shell", cli_shell, 0, -1, 0 },
{ "search", cli_search, 1, -1, 0 },
{ NULL },
};
"repo compose PATH PACKAGES...\n"
"repolist\n"
"requires PATTERN\n"
- "shell [OPTIONS...]\n"
+ "shell [OPTIONS...] [COMMAND...]\n"
"search [OPTIONS...] PATTERN";
static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
ERROR:
// Drop to a shell for debugging
if (pakfire_build_has_flag(build, PAKFIRE_BUILD_INTERACTIVE))
- pakfire_build_shell(build);
+ pakfire_build_shell(build, NULL);
return r;
}
/*
Drops the user into a shell
*/
-PAKFIRE_EXPORT int pakfire_build_shell(struct pakfire_build* build) {
+PAKFIRE_EXPORT int pakfire_build_shell(struct pakfire_build* build, const char* argv[]) {
int r;
// Initialize the build environment
if (r)
return r;
- // Run shell
+ // Run the command (if given)
+ if (argv)
+ return pakfire_jail_exec(build->jail, argv, 0);
+
+ // Otherwise run the shell
return pakfire_jail_shell(build->jail);
}
int pakfire_build_set_ccache_path(struct pakfire_build* build, const char* path);
int pakfire_build_set_target(struct pakfire_build* build, const char* target);
-int pakfire_build_shell(struct pakfire_build* build);
+int pakfire_build_shell(struct pakfire_build* build, const char* argv[]);
int pakfire_build_exec(struct pakfire_build* build, const char* path);