From a48122af435cc3641aaff9df367fc7b0b1912156 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 28 Nov 2025 15:48:46 -0600 Subject: [PATCH] EngineLauncher: Guard against missing args, and strip the windows service "stop" flag to correctly pass the port/token data on a shutdown request --- .../main/java/org/red5/daemon/EngineLauncher.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/org/red5/daemon/EngineLauncher.java b/service/src/main/java/org/red5/daemon/EngineLauncher.java index af3505de9..c8d033c55 100644 --- a/service/src/main/java/org/red5/daemon/EngineLauncher.java +++ b/service/src/main/java/org/red5/daemon/EngineLauncher.java @@ -66,13 +66,18 @@ public static void main(String[] args) { */ public static void windowsService(String args[]) { String cmd = "start"; - if (args.length > 0) { + if (args != null && args.length > 0) { cmd = args[0]; } if ("start".equals(cmd)) { engineLauncherInstance.windowsStart(); } else { - commandLineArgs = args; + // drop the leading control arg so stop receives only port / token + if (args != null && args.length > 1) { + commandLineArgs = Arrays.copyOfRange(args, 1, args.length); + } else { + commandLineArgs = new String[0]; + } engineLauncherInstance.windowsStop(); } } @@ -157,7 +162,10 @@ private void initialize() { public void terminate() { if (stopped.compareAndSet(false, true)) { System.out.printf("Stopping Red5 with args: %s%n", Arrays.toString(commandLineArgs)); - if (commandLineArgs == null || commandLineArgs.length < 2) { + if (commandLineArgs == null) { + commandLineArgs = new String[0]; + } + if (commandLineArgs.length < 2) { // there should be 40+ characters worth of args (port + token) // use the default port of 9999 String port = "9999";