Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/daemon/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/daemon/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <sys/proc_info.h>
#include <sys/stat.h>
#include <unistd.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__NetBSD__)
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading