The branch main has been updated by bapt:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=9f2ad7c09709e01ff6b856df0315e91ddc20df32

commit 9f2ad7c09709e01ff6b856df0315e91ddc20df32
Author:     Baptiste Daroussin <[email protected]>
AuthorDate: 2026-05-05 12:00:41 +0000
Commit:     Baptiste Daroussin <[email protected]>
CommitDate: 2026-05-05 13:39:58 +0000

    init: allow to specify a custom path for rc(8)
    
    This is useful for testing alternative service managers
    without modifying /etc/rc
    
    MFC After:      1 weeks
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D56828
---
 sbin/init/init.8 | 10 +++++++++-
 sbin/init/init.c | 18 +++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/sbin/init/init.8 b/sbin/init/init.8
index 85b1db2ddf06..f562efde0b51 100644
--- a/sbin/init/init.8
+++ b/sbin/init/init.8
@@ -28,7 +28,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd July 22, 2021
+.Dd May 5, 2026
 .Dt INIT 8
 .Os
 .Sh 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;

Reply via email to