| 48 | #define CHILD_ADDR "127.0.0.1" |
| 49 | |
| 50 | static std::filesystem::path get_server_exec_path() { |
| 51 | #if defined(_WIN32) |
| 52 | wchar_t buf[32768] = { 0 }; // Large buffer to handle long paths |
| 53 | DWORD len = GetModuleFileNameW(nullptr, buf, _countof(buf)); |
| 54 | if (len == 0 || len >= _countof(buf)) { |
| 55 | throw std::runtime_error("GetModuleFileNameW failed or path too long"); |
| 56 | } |
| 57 | return std::filesystem::path(buf); |
| 58 | #elif defined(__APPLE__) && defined(__MACH__) |
| 59 | char small_path[PATH_MAX]; |
| 60 | uint32_t size = sizeof(small_path); |
| 61 | |
| 62 | if (_NSGetExecutablePath(small_path, &size) == 0) { |
| 63 | // resolve any symlinks to get absolute path |
| 64 | try { |
| 65 | return std::filesystem::canonical(std::filesystem::path(small_path)); |
| 66 | } catch (...) { |
| 67 | return std::filesystem::path(small_path); |
| 68 | } |
| 69 | } else { |
| 70 | // buffer was too small, allocate required size and call again |
| 71 | std::vector<char> buf(size); |
| 72 | if (_NSGetExecutablePath(buf.data(), &size) == 0) { |
| 73 | try { |
| 74 | return std::filesystem::canonical(std::filesystem::path(buf.data())); |
| 75 | } catch (...) { |
| 76 | return std::filesystem::path(buf.data()); |
| 77 | } |
| 78 | } |
| 79 | throw std::runtime_error("_NSGetExecutablePath failed after buffer resize"); |
| 80 | } |
| 81 | #else |
| 82 | char path[FILENAME_MAX]; |
| 83 | ssize_t count = readlink("/proc/self/exe", path, FILENAME_MAX); |
| 84 | if (count <= 0) { |
| 85 | throw std::runtime_error("failed to resolve /proc/self/exe"); |
| 86 | } |
| 87 | return std::filesystem::path(std::string(path, count)); |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | static void unset_reserved_args(common_preset & preset, bool unset_model_args) { |
| 92 | preset.unset_option("LLAMA_ARG_SSL_KEY_FILE"); |
no test coverage detected