]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server: re-inject subcommand when router spawns children under unified binary (#23442)
authorPascal <redacted>
Thu, 21 May 2026 08:09:19 +0000 (10:09 +0200)
committerGitHub <redacted>
Thu, 21 May 2026 08:09:19 +0000 (10:09 +0200)
app/llama.cpp
tools/server/server-models.cpp

index e149975d28c0e9d0d879d41ae5b867fd982c4b74..b0b86fd47d9d13cd4f6ee28bb1ddc8c8be39149c 100644 (file)
@@ -1,6 +1,7 @@
 #include "build-info.h"
 
 #include <cstdio>
+#include <cstdlib>
 #include <string>
 #include <vector>
 
@@ -77,6 +78,14 @@ int main(int argc, char ** argv) {
 
     for (const auto & cmd : cmds) {
         if (matches(arg, cmd)) {
+
+            // router spawns children through this same binary, it needs the
+            // subcommand to relaunch as 'llama serve' and not bare options
+#ifdef _WIN32
+            _putenv_s("LLAMA_APP_CMD", cmd.name);
+#else
+            setenv("LLAMA_APP_CMD", cmd.name, 1);
+#endif
             return cmd.func(argc - 1, argv + 1);
         }
     }
index ccf42320f77a0daeb0375727ca0711999c44fb8c..47b6c2a4ec038f6b4e3e25ae45484103394675b0 100644 (file)
@@ -14,6 +14,7 @@
 #include <mutex>
 #include <condition_variable>
 #include <cstring>
+#include <cstdlib>
 #include <atomic>
 #include <chrono>
 #include <queue>
@@ -159,6 +160,13 @@ void server_model_meta::update_args(common_preset_context & ctx_preset, std::str
     // TODO: maybe validate preset before rendering ?
     // render args
     args = preset.to_args(bin_path);
+
+    // unified binary dispatches by subcommand, re-inject it right after the
+    // binary path so the child starts as 'llama serve ...' not 'llama ...'
+    const char * app_cmd = std::getenv("LLAMA_APP_CMD");
+    if (app_cmd != nullptr && app_cmd[0] != '\0' && !bin_path.empty()) {
+        args.insert(args.begin() + 1, app_cmd);
+    }
 }
 
 void server_model_meta::update_caps() {