This change allows init(8) to run in a jail enviroment to emulate a bootstrap
of another full-blown userland environment. While most of the tasks
handled by init(8) are useless inside a jail, invoking /sbin/init as the
initial process is more natural for Unix-like OS and watching terminal
ports is still useful.
For example, you can get a login prompt to a jail using
"cu -l /dev/nmdm0A" if you have the following configuration:
/etc/jail.conf on the host environment:
exec.start = "/sbin/init";
/etc/ttys inside a jail:
nmdm0B "/usr/libexec/getty 3wire" xterm on secure
Note that your jail environment must have devfs mounted and
unhide /dev/nmdm* path.
init(8) with this patch runs inside a jail in the following way:
- It calls fork() and the child process handles the state machine transition.
- After the child process finishes to run the rc(8) script, it will send a notification to the parent, and then the parent process terminates. The jail(8) utility typically blocks until this notification arrives. This reproduces the behavior of running the rc(8) script and then entering the multi-user mode on the host environment.
- The child process will read /etc/ttys and handle terminal ports in the infinite loop after the parent terminates.