diff --git a/core/utils.c b/core/utils.c index 54ae5ac2..72c05c36 100644 --- a/core/utils.c +++ b/core/utils.c @@ -435,6 +435,33 @@ void uwsgi_as_root() { } #ifdef UWSGI_HAS_FREEBSD_LIBJAIL + if (uwsgi.jail_attach && !uwsgi.reloads) { + struct jailparam jparam; + uwsgi_log("attaching to FreeBSD jail %s ...\n", uwsgi.jail_attach); + if (!is_a_number(uwsgi.jail_attach)) { + if (jailparam_init(&jparam, "name")) { + uwsgi_error("jailparam_init()"); + exit(1); + } + } + else { + if (jailparam_init(&jparam, "jid")) { + uwsgi_error("jailparam_init()"); + exit(1); + } + } + jailparam_import(&jparam, uwsgi.jail_attach); + int jail_id = jailparam_set(&jparam, 1, JAIL_UPDATE|JAIL_ATTACH); + if (jail_id < 0) { + uwsgi_error("jailparam_set()"); + exit(1); + } + + jailparam_free(&jparam, 1); + uwsgi_log("--- running in FreeBSD jail %d ---\n", jail_id); + in_jail = 1; + } + if (uwsgi.jail2 && !uwsgi.reloads) { struct uwsgi_string_list *usl = NULL; unsigned nparams = 0; diff --git a/core/uwsgi.c b/core/uwsgi.c index 5f4865f4..778971a2 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -315,6 +315,7 @@ static struct uwsgi_option uwsgi_base_options[] = { #ifdef UWSGI_HAS_FREEBSD_LIBJAIL {"jail2", required_argument, 0, "add an option to the FreeBSD jail", uwsgi_opt_add_string_list, &uwsgi.jail2, 0}, {"libjail", required_argument, 0, "add an option to the FreeBSD jail", uwsgi_opt_add_string_list, &uwsgi.jail2, 0}, + {"jail-attach", required_argument, 0, "attach to the FreeBSD jail", uwsgi_opt_set_str, &uwsgi.jail_attach, 0}, #endif #endif {"refork", no_argument, 0, "fork() again after privileges drop. Useful for jailing systems", uwsgi_opt_true, &uwsgi.refork, 0}, diff --git a/uwsgi.h b/uwsgi.h index bff130a0..c79aebf5 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1835,6 +1835,7 @@ struct uwsgi_server { #endif struct uwsgi_string_list *jail2; char *jidfile; + char *jail_attach; #endif int refork;