|
3 | 3 | #include "services/engine_service.h" |
4 | 4 | #include "utils/cortex_utils.h" |
5 | 5 | #include "utils/file_manager_utils.h" |
| 6 | +#include "utils/process/utils.h" |
6 | 7 |
|
7 | 8 | #if defined(_WIN32) || defined(_WIN64) |
8 | 9 | #include "utils/widechar_conv.h" |
@@ -103,25 +104,26 @@ bool ServerStartCmd::Exec(const std::string& host, int port, |
103 | 104 | } |
104 | 105 |
|
105 | 106 | #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(); |
108 | 113 |
|
| 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); |
109 | 123 | if (pid < 0) { |
110 | 124 | // Fork failed |
111 | 125 | std::cerr << "Could not start server: " << std::endl; |
112 | 126 | 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); |
125 | 127 | } else { |
126 | 128 | // Parent process |
127 | 129 | if (!TryConnectToServer(host, port)) { |
|
0 commit comments