From 68f78d914b221763476e6f17a0d0c48183eeb8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 28 Apr 2019 17:56:30 +0200 Subject: child: allow binfmt_misc to be preserved This should allow chrooting to non-native systems using qemu. --- main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 0f4815c..058aa3b 100644 --- a/main.c +++ b/main.c @@ -41,10 +41,16 @@ static const char doc[] = "Tool using Linux namespaces to provide root like func struct opts { char **child_argv; size_t child_argc; + bool binfmt; +}; + +enum option_key { + OPT_BINFMT = 260, }; static struct argp_option options[] = { {"debug", 'd', NULL, 0, "Report uroot operations.", 0}, + {"binfmt", OPT_BINFMT, NULL, 0, "Preserve registered misc binary format handlers.", 0}, {NULL} }; @@ -54,6 +60,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { case 'd': // TODO logging break; + case OPT_BINFMT: + opts->binfmt = true; + break; case ARGP_KEY_ARGS: opts->child_argc = state->argc - state->next; opts->child_argv = malloc((opts->child_argc + 1) * sizeof *opts->child_argv); @@ -64,6 +73,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { case ARGP_KEY_INIT: opts->child_argv = NULL; opts->child_argc = 0; + opts->binfmt = false; break; default: return ARGP_ERR_UNKNOWN; @@ -87,7 +97,8 @@ int main(int argc, char **argv) { .ppid = getpid(), .argc = opts.child_argc, .argv = opts.child_argv, - .sigpipe = sigpipe_new() + .sigpipe = sigpipe_new(), + .binfmt = opts.binfmt, }; uint8_t stack[STACK_SIZE]; -- cgit v1.2.3