diff --git a/src/daemon/ipc.c b/src/daemon/ipc.c index 0c1ae652c..4426877db 100644 --- a/src/daemon/ipc.c +++ b/src/daemon/ipc.c @@ -3023,6 +3023,14 @@ uint64_t cbm_daemon_ipc_connection_peer_pid(const cbm_daemon_ipc_connection_t *c return 0; } return (uint64_t)peer_pid; +#elif defined(SOL_LOCAL) && defined(LOCAL_PEEREID) + struct unpcbid peer_id; + socklen_t length = sizeof(peer_id); + if (getsockopt(connection->fd, SOL_LOCAL, LOCAL_PEEREID, &peer_id, &length) != 0 || + length != sizeof(peer_id) || peer_id.unp_pid <= 0) { + return 0; + } + return (uint64_t)peer_id.unp_pid; #else return 0; #endif diff --git a/src/daemon/runtime.c b/src/daemon/runtime.c index 1d08051bd..211a89de0 100644 --- a/src/daemon/runtime.c +++ b/src/daemon/runtime.c @@ -30,7 +30,7 @@ #include #include #include -#elif defined(__linux__) +#elif defined(__linux__) || defined(__NetBSD__) #include #include #include @@ -135,7 +135,7 @@ typedef struct { HANDLE file; BY_HANDLE_FILE_INFORMATION information; LARGE_INTEGER size; -#elif defined(__APPLE__) || defined(__linux__) +#elif defined(__APPLE__) || defined(__linux__) || defined(__NetBSD__) int fd; struct stat status; #endif @@ -490,7 +490,7 @@ static bool runtime_activation_response_decode( static uint64_t runtime_current_process_id(void) { #ifdef _WIN32 return (uint64_t)GetCurrentProcessId(); -#elif defined(__APPLE__) || defined(__linux__) +#elif defined(__APPLE__) || defined(__linux__) || defined(__NetBSD__) return (uint64_t)getpid(); #else return 0; @@ -504,7 +504,7 @@ static void runtime_process_image_reference_init(runtime_process_image_reference memset(reference, 0, sizeof(*reference)); #ifdef _WIN32 reference->file = INVALID_HANDLE_VALUE; -#elif defined(__APPLE__) || defined(__linux__) +#elif defined(__APPLE__) || defined(__linux__) || defined(__NetBSD__) reference->fd = -1; #endif } @@ -518,7 +518,7 @@ static bool runtime_process_image_reference_release(runtime_process_image_refere if (reference->file != INVALID_HANDLE_VALUE && !CloseHandle(reference->file)) { ok = false; } -#elif defined(__APPLE__) || defined(__linux__) +#elif defined(__APPLE__) || defined(__linux__) || defined(__NetBSD__) if (reference->fd >= 0 && close(reference->fd) != 0) { ok = false; } @@ -658,7 +658,7 @@ static bool runtime_mac_process_maps_file_executable(int process_id, const struc return false; } -#elif defined(__linux__) +#elif defined(__linux__) || defined(__NetBSD__) static bool runtime_linux_stat_same_image(const struct stat *first, const struct stat *second) { return first && second && S_ISREG(first->st_mode) && S_ISREG(second->st_mode) && @@ -753,7 +753,7 @@ static bool runtime_process_image_reference_acquire( } else if (fd >= 0) { (void)close(fd); } -#elif defined(__linux__) +#elif defined(__linux__) || defined(__NetBSD__) char proc_path[64]; int written = snprintf(proc_path, sizeof(proc_path), "/proc/%llu", (unsigned long long)process_id); @@ -827,7 +827,7 @@ static bool runtime_process_image_reference_matches_process( runtime_mac_stat_same(&active->status, &peer.status); bool released = runtime_process_image_reference_release(&peer); return same && released; -#elif defined(__linux__) +#elif defined(__linux__) || defined(__NetBSD__) runtime_process_image_reference_t peer; runtime_process_image_reference_init(&peer); bool same = runtime_process_image_reference_acquire(process_id, &peer, NULL);