NAME @@ -396,6 +396,14 @@ back to the default, so that the .Pa /etc/rc script is executed with the standard shell .Pa /bin/sh . +.It Va init_rc +If set to a valid file name in the root file system, +overrides the default path to +.Xr rc 8 +.Pq Pa /etc/rc . +This is useful for testing alternative service managers +without modifying the default +.Pa /etc/rc . .It Va init_path Specifies the path used to search for the init binary. More than one binary can be listed in the string, diff --git a/sbin/init/init.c b/sbin/init/init.c index d28501053c7f..db680c7f73bd 100644 --- a/sbin/init/init.c +++ b/sbin/init/init.c @@ -1025,11 +1025,23 @@ static state_func_t runcom(void) { state_func_t next_transition; + char runcom_path[PATH_MAX]; + const char *rc_script; - BOOTTRACE("/etc/rc starting..."); - if ((next_transition = run_script(_PATH_RUNCOM)) != NULL) + /* + * Allow overriding /etc/rc via the init_rc kenv variable. + * This is useful for testing alternative service managers + * without modifying /etc/rc. + */ + if (kenv(KENV_GET, "init_rc", runcom_path, sizeof(runcom_path)) > 0) + rc_script = runcom_path; + else + rc_script = _PATH_RUNCOM; + + BOOTTRACE("%s starting...", rc_script); + if ((next_transition = run_script(rc_script)) != NULL) return next_transition; - BOOTTRACE("/etc/rc finished"); + BOOTTRACE("%s finished", rc_script); runcom_mode = AUTOBOOT; /* the default */ return (state_func_t) read_ttys;