Skip to content

Commit 0dbf1e7

Browse files
committed
add fallback logic
1 parent 895aabb commit 0dbf1e7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tools/server/server-models.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,21 @@ server_models::server_models(
139139
const common_params & params,
140140
int argc,
141141
char ** argv,
142-
char ** envp) : base_params(params), server_binary_path(get_server_exec_path().string()) {
142+
char ** envp) : base_params(params) {
143143
for (int i = 0; i < argc; i++) {
144144
base_args.push_back(std::string(argv[i]));
145145
}
146146
for (char ** env = envp; *env != nullptr; env++) {
147147
base_env.push_back(std::string(*env));
148148
}
149+
GGML_ASSERT(!base_args.empty());
150+
// set binary path
151+
try {
152+
base_args[0] = get_server_exec_path().string();
153+
} catch (const std::exception & e) {
154+
LOG_WRN("failed to get server executable path: %s\n", e.what());
155+
LOG_WRN("using original argv[0] as fallback: %s\n", base_args[0].c_str());
156+
}
149157
// TODO: allow refreshing cached model list
150158
// add cached models
151159
auto cached_models = common_list_cached_models();
@@ -382,9 +390,6 @@ void server_models::load(const std::string & name, bool auto_load) {
382390
}
383391
}
384392

385-
// set executable path
386-
child_args[0] = server_binary_path;
387-
388393
// set model args
389394
add_or_replace_arg(child_args, "--port", std::to_string(inst.meta.port));
390395
add_or_replace_arg(child_args, "--alias", inst.meta.name);

tools/server/server-models.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ struct server_models {
8484
common_params base_params;
8585
std::vector<std::string> base_args;
8686
std::vector<std::string> base_env;
87-
std::string server_binary_path;
8887

8988
void update_meta(const std::string & name, const server_model_meta & meta);
9089

0 commit comments

Comments
 (0)