Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit c6f86fd

Browse files
chore: cleanup (#1849)
* chore: cleanup * chore: spawn process --------- Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent 193946e commit c6f86fd

File tree

8 files changed

+257
-230
lines changed

8 files changed

+257
-230
lines changed

engine/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ add_executable(${TARGET_NAME} main.cc
149149
${CMAKE_CURRENT_SOURCE_DIR}/extensions/python-engine/python_engine.cc
150150

151151
${CMAKE_CURRENT_SOURCE_DIR}/utils/dylib_path_manager.cc
152+
${CMAKE_CURRENT_SOURCE_DIR}/utils/process/utils.cc
152153

153154
${CMAKE_CURRENT_SOURCE_DIR}/extensions/remote-engine/remote_engine.cc
154155

engine/cli/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ add_executable(${TARGET_NAME} main.cc
9595
${CMAKE_CURRENT_SOURCE_DIR}/../utils/file_manager_utils.cc
9696
${CMAKE_CURRENT_SOURCE_DIR}/../utils/curl_utils.cc
9797
${CMAKE_CURRENT_SOURCE_DIR}/../utils/system_info_utils.cc
98+
${CMAKE_CURRENT_SOURCE_DIR}/../utils/process/utils.cc
9899
)
99100

100101
target_link_libraries(${TARGET_NAME} PRIVATE CLI11::CLI11)

engine/cli/commands/server_start_cmd.cc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "services/engine_service.h"
44
#include "utils/cortex_utils.h"
55
#include "utils/file_manager_utils.h"
6+
#include "utils/process/utils.h"
67

78
#if defined(_WIN32) || defined(_WIN64)
89
#include "utils/widechar_conv.h"
@@ -103,25 +104,26 @@ bool ServerStartCmd::Exec(const std::string& host, int port,
103104
}
104105

105106
#else
106-
// Unix-like system-specific code to fork a child process
107-
pid_t pid = fork();
107+
std::vector<std::string> commands;
108+
// Some engines requires to add lib search path before process being created
109+
auto download_srv = std::make_shared<DownloadService>();
110+
auto dylib_path_mng = std::make_shared<cortex::DylibPathManager>();
111+
auto db_srv = std::make_shared<DatabaseService>();
112+
EngineService(download_srv, dylib_path_mng, db_srv).RegisterEngineLibPath();
108113

114+
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
115+
commands.push_back(p);
116+
commands.push_back("--config_file_path");
117+
commands.push_back(get_config_file_path());
118+
commands.push_back("--data_folder_path");
119+
commands.push_back(get_data_folder_path());
120+
commands.push_back("--loglevel");
121+
commands.push_back(log_level_);
122+
auto pid = cortex::process::SpawnProcess(commands);
109123
if (pid < 0) {
110124
// Fork failed
111125
std::cerr << "Could not start server: " << std::endl;
112126
return false;
113-
} else if (pid == 0) {
114-
// Some engines requires to add lib search path before process being created
115-
auto download_srv = std::make_shared<DownloadService>();
116-
auto dylib_path_mng = std::make_shared<cortex::DylibPathManager>();
117-
auto db_srv = std::make_shared<DatabaseService>();
118-
EngineService(download_srv, dylib_path_mng, db_srv).RegisterEngineLibPath();
119-
120-
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
121-
execl(p.c_str(), exe.c_str(), "--start-server", "--config_file_path",
122-
get_config_file_path().c_str(), "--data_folder_path",
123-
get_data_folder_path().c_str(), "--loglevel", log_level_.c_str(),
124-
(char*)0);
125127
} else {
126128
// Parent process
127129
if (!TryConnectToServer(host, port)) {

0 commit comments

Comments
 (0)