From e97a37df294b40ca45dbc4eecb494c6781068148 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Fri, 13 Feb 2026 14:35:17 -0500 Subject: [PATCH] fix: preserve legacy execlp() behavior for commands without % tokens If EventStartCommand/EventEndCommand contains a % character, use the new token substitution (%EID%, %MID%, %EC%) with sh -c execution. Otherwise, fall back to the original execlp() behavior that passes event_id and monitor_id as $1 and $2, so existing installs are not broken. Co-Authored-By: Claude Opus 4.6 --- src/zm_monitor.cpp | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 291e25684..2af027394 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -3238,13 +3238,23 @@ Event * Monitor::openEvent( logTerm(); int fdlimit = (int)sysconf(_SC_OPEN_MAX); for (int i = 0; i < fdlimit; i++) close(i); - std::string cmd = ReplaceAll(ReplaceAll( - ReplaceAll(event_start_command, "%EID%", std::to_string(event->Id())), - "%MID%", std::to_string(event->MonitorId())), - "%EC%", ShellEscape(cause)); - execl("/bin/sh", "sh", "-c", cmd.c_str(), nullptr); - logInit(log_id.c_str()); - Error("Error execing %s: %s", cmd.c_str(), strerror(errno)); + if (event_start_command.find('%') != std::string::npos) { + std::string cmd = ReplaceAll(ReplaceAll( + ReplaceAll(event_start_command, "%EID%", std::to_string(event->Id())), + "%MID%", std::to_string(event->MonitorId())), + "%EC%", ShellEscape(cause)); + execl("/bin/sh", "sh", "-c", cmd.c_str(), nullptr); + logInit(log_id.c_str()); + Error("Error execing %s: %s", cmd.c_str(), strerror(errno)); + } else { + execlp(event_start_command.c_str(), + event_start_command.c_str(), + std::to_string(event->Id()).c_str(), + std::to_string(event->MonitorId()).c_str(), + nullptr); + logInit(log_id.c_str()); + Error("Error execing %s: %s", event_start_command.c_str(), strerror(errno)); + } std::quick_exit(0); } } @@ -3280,12 +3290,22 @@ void Monitor::closeEvent() { logTerm(); int fdlimit = (int)sysconf(_SC_OPEN_MAX); for (int i = 0; i < fdlimit; i++) close(i); - std::string cmd = ReplaceAll( - ReplaceAll(command, "%EID%", std::to_string(event_id)), - "%MID%", std::to_string(monitor_id)); - execl("/bin/sh", "sh", "-c", cmd.c_str(), nullptr); - logInit(log_id.c_str()); - Error("Error execing %s: %s", cmd.c_str(), strerror(errno)); + if (command.find('%') != std::string::npos) { + std::string cmd = ReplaceAll( + ReplaceAll(command, "%EID%", std::to_string(event_id)), + "%MID%", std::to_string(monitor_id)); + execl("/bin/sh", "sh", "-c", cmd.c_str(), nullptr); + logInit(log_id.c_str()); + Error("Error execing %s: %s", cmd.c_str(), strerror(errno)); + } else { + execlp(command.c_str(), + command.c_str(), + std::to_string(event_id).c_str(), + std::to_string(monitor_id).c_str(), + nullptr); + logInit(log_id.c_str()); + Error("Error execing %s: %s", command.c_str(), strerror(errno)); + } std::quick_exit(0); } }