Commit 6058a6bd4e for frr

commit 6058a6bd4eca5a6ae2821f7da90738be47fb446d
Author: Vincent Jardin <vjardin@free.fr>
Date:   Mon Nov 9 19:11:07 2026 +0100

    vtysh: fix crash on "terminal monitor" outside interactive mode

    vtysh only creates its event loop in vtysh_rl_run(), i.e. for the
    interactive shell.

    Any commands provided with -c (or from -f/-b) run before that, and
    "terminal monitor" then passes a NULL event loop to event_add_read():

      frame #0: libfrr`_event_add_read_write(m=0x0, func=vtysh_log_read, fd=5)
      frame #1: vtysh`vtysh_terminal_monitor_magic at vtysh.c:4682
      frame #8: vtysh`main at vtysh_main.c:804

    Reject the command with a warning in that case instead of segfaulting.

    Signed-off-by: Vincent Jardin <vjardin@free.fr>

diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index ada903b4b9..1c35b71bba 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -4880,6 +4880,11 @@ DEFPY (vtysh_terminal_monitor,
 	int ret_all = CMD_SUCCESS, ret, fd;
 	size_t i, ok = 0;

+	if (!master) {
+		vty_out(vty, "%% terminal monitor is only available in interactive vtysh\n");
+		return CMD_WARNING;
+	}
+
 	for (i = 0; i < array_size(vtysh_client); i++) {
 		struct vtysh_client *vclient = &vtysh_client[i];