Index: usr.sbin/jail/command.c =================================================================== --- usr.sbin/jail/command.c +++ usr.sbin/jail/command.c @@ -148,7 +148,8 @@ if (j->comstring == NULL || j->comstring->len == 0 || (create_failed && (comparam == IP_EXEC_PRESTART || comparam == IP_EXEC_CREATED || comparam == IP_EXEC_START || - comparam == IP_COMMAND || comparam == IP_EXEC_POSTSTART))) + comparam == IP_COMMAND || comparam == IP_EXEC_POSTSTART || + comparam == IP_EXEC_PREPARE))) continue; switch (run_command(j)) { case -1: Index: usr.sbin/jail/config.c =================================================================== --- usr.sbin/jail/config.c +++ usr.sbin/jail/config.c @@ -65,21 +65,24 @@ [IP_ALLOW_DYING] = {"allow.dying", PF_INTERNAL | PF_BOOL}, [IP_COMMAND] = {"command", PF_INTERNAL}, [IP_DEPEND] = {"depend", PF_INTERNAL}, + /* exec options */ [IP_EXEC_CLEAN] = {"exec.clean", PF_INTERNAL | PF_BOOL}, [IP_EXEC_CONSOLELOG] = {"exec.consolelog", PF_INTERNAL}, [IP_EXEC_FIB] = {"exec.fib", PF_INTERNAL | PF_INT}, [IP_EXEC_JAIL_USER] = {"exec.jail_user", PF_INTERNAL}, - [IP_EXEC_POSTSTART] = {"exec.poststart", PF_INTERNAL}, - [IP_EXEC_POSTSTOP] = {"exec.poststop", PF_INTERNAL}, - [IP_EXEC_PRESTART] = {"exec.prestart", PF_INTERNAL}, - [IP_EXEC_PRESTOP] = {"exec.prestop", PF_INTERNAL}, - [IP_EXEC_CREATED] = {"exec.created", PF_INTERNAL}, - [IP_EXEC_START] = {"exec.start", PF_INTERNAL}, - [IP_EXEC_STOP] = {"exec.stop", PF_INTERNAL}, [IP_EXEC_SYSTEM_JAIL_USER]= {"exec.system_jail_user", PF_INTERNAL | PF_BOOL}, [IP_EXEC_SYSTEM_USER] = {"exec.system_user", PF_INTERNAL}, [IP_EXEC_TIMEOUT] = {"exec.timeout", PF_INTERNAL | PF_INT}, + /* exec commands */ + [IP_EXEC_PREPARE] = {"exec.prepare", PF_INTERNAL}, + [IP_EXEC_PRESTART] = {"exec.prestart", PF_INTERNAL}, + [IP_EXEC_CREATED] = {"exec.created", PF_INTERNAL}, + [IP_EXEC_START] = {"exec.start", PF_INTERNAL}, + [IP_EXEC_POSTSTART] = {"exec.poststart", PF_INTERNAL}, + [IP_EXEC_PRESTOP] = {"exec.prestop", PF_INTERNAL}, + [IP_EXEC_STOP] = {"exec.stop", PF_INTERNAL}, + [IP_EXEC_POSTSTOP] = {"exec.poststop", PF_INTERNAL}, #if defined(INET) || defined(INET6) [IP_INTERFACE] = {"interface", PF_INTERNAL}, [IP_IP_HOSTNAME] = {"ip_hostname", PF_INTERNAL | PF_BOOL}, Index: usr.sbin/jail/jail.8 =================================================================== --- usr.sbin/jail/jail.8 +++ usr.sbin/jail/jail.8 @@ -721,6 +721,11 @@ .Pp The pseudo-parameters are: .Bl -tag -width indent +.It Va exec.prepare +Command(s) to run in the system environment to prepare a jail for creation. +These commands are executed before assigning IP addresses and before mounting +filesystems, so they may be used to create a new jail filesystem if it does +not already exist. .It Va exec.prestart Command(s) to run in the system environment before a jail is created. .It Va exec.created Index: usr.sbin/jail/jail.c =================================================================== --- usr.sbin/jail/jail.c +++ usr.sbin/jail/jail.c @@ -87,6 +87,7 @@ static const enum intparam startcommands[] = { IP__NULL, + IP_EXEC_PREPARE, #ifdef INET IP__IP4_IFADDR, #endif Index: usr.sbin/jail/jailp.h =================================================================== --- usr.sbin/jail/jailp.h +++ usr.sbin/jail/jailp.h @@ -81,20 +81,23 @@ IP_ALLOW_DYING, /* Allow making changes to a dying jail */ IP_COMMAND, /* Command run inside jail at creation */ IP_DEPEND, /* Jail starts after (stops before) another */ + /* exec options */ IP_EXEC_CLEAN, /* Run commands in a clean environment */ IP_EXEC_CONSOLELOG, /* Redirect optput for commands run in jail */ IP_EXEC_FIB, /* Run jailed commands with this FIB */ IP_EXEC_JAIL_USER, /* Run jailed commands as this user */ - IP_EXEC_POSTSTART, /* Commands run outside jail after creating */ - IP_EXEC_POSTSTOP, /* Commands run outside jail after removing */ + IP_EXEC_SYSTEM_JAIL_USER,/* Get jail_user from system passwd file */ + IP_EXEC_SYSTEM_USER, /* Run non-jailed commands as this user */ + IP_EXEC_TIMEOUT, /* Time to wait for a command to complete */ + /* exec commands */ + IP_EXEC_PREPARE, /* Commands run outside jail before addrs and mounting */ IP_EXEC_PRESTART, /* Commands run outside jail before creating */ - IP_EXEC_PRESTOP, /* Commands run outside jail before removing */ IP_EXEC_CREATED, /* Commands run outside jail right after it was started */ IP_EXEC_START, /* Commands run inside jail on creation */ + IP_EXEC_POSTSTART, /* Commands run outside jail after creating */ + IP_EXEC_PRESTOP, /* Commands run outside jail before removing */ IP_EXEC_STOP, /* Commands run inside jail on removal */ - IP_EXEC_SYSTEM_JAIL_USER,/* Get jail_user from system passwd file */ - IP_EXEC_SYSTEM_USER, /* Run non-jailed commands as this user */ - IP_EXEC_TIMEOUT, /* Time to wait for a command to complete */ + IP_EXEC_POSTSTOP, /* Commands run outside jail after removing */ #if defined(INET) || defined(INET6) IP_INTERFACE, /* Add IP addresses to this interface */ IP_IP_HOSTNAME, /* Get jail IP address(es) from hostname */