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 <noreply@anthropic.com>
This commit is contained in:
Pliable Pixels
2026-02-13 14:35:17 -05:00
committed by Isaac Connor
parent cf3f44a466
commit e97a37df29

View File

@@ -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);
}
}