Index: libexec/rtld-elf/rtld.c =================================================================== --- libexec/rtld-elf/rtld.c +++ libexec/rtld-elf/rtld.c @@ -421,6 +421,7 @@ md_abi_variant_hook(aux_info); fd = -1; + jid = -1; if (aux_info[AT_EXECFD] != NULL) { fd = aux_info[AT_EXECFD]->a_un.a_val; } else { @@ -779,6 +780,11 @@ /* Return the exit procedure and the program entry point. */ *exit_proc = rtld_exit; *objp = obj_main; + + /* Attach to a jail */ + if (jid > 0) + jail_attach(jid); + return (func_ptr_type) obj_main->entry; } @@ -1820,6 +1826,7 @@ struct stat hint_stat; unsigned int SLPndx, hintndx, fndx, fcount; int fd; + int jid; size_t flen; uint32_t dl; bool skip; @@ -5510,6 +5517,20 @@ } *fdp = fd; break; + } else if (opt == 'j') { + if (j != arglen - 1) { + /* -j must be the last option in, e.g., -abcj */ + _rtld_error("Invalid options: %s", arg); + rtld_die(); + } + i++; + jid = parse_integer(argv[i]); + if (fd == -1) { + _rtld_error("Invalid JID: '%s'", + argv[i]); + rtld_die(); + } + break; } else if (opt == 'p') { *use_pathp = true; } else { @@ -5554,12 +5575,13 @@ print_usage(const char *argv0) { - rtld_printf("Usage: %s [-h] [-f ] [--] []\n" + rtld_printf("Usage: %s [-h] [-f ] [-j ] [--] []\n" "\n" "Options:\n" " -h Display this help message\n" " -p Search in PATH for named binary\n" " -f Execute instead of searching for \n" + " -j Execute after attaching to jail with JID \n" " -- End of RTLD options\n" " Name of process to execute\n" " Arguments to the executed process\n", argv0);