mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
LibCore: Fix LocalSocket.cpp
build on FreeBSD
This fixes the build on FreeBSD by chagning LOCAL_PEERPID to LOCAL_PEERCRED inside a ifdef
This commit is contained in:
parent
dc3fa1c2e5
commit
c0a7e0ad23
1 changed files with 18 additions and 7 deletions
|
@ -11,6 +11,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#if defined(__FreeBSD__)
|
||||||
|
# include <sys/ucred.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef SOCK_NONBLOCK
|
#ifndef SOCK_NONBLOCK
|
||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
|
@ -58,22 +61,30 @@ pid_t LocalSocket::peer_pid() const
|
||||||
#ifdef AK_OS_MACOS
|
#ifdef AK_OS_MACOS
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
socklen_t pid_size = sizeof(pid);
|
socklen_t pid_size = sizeof(pid);
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
if (getsockopt(fd(), SOL_LOCAL, LOCAL_PEERPID, &pid, &pid_size) < 0) {
|
struct xucred creds = {};
|
||||||
dbgln("LocalSocket: getsockopt failed, {}", strerror(errno));
|
socklen_t creds_size = sizeof(creds);
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
return pid;
|
|
||||||
#else
|
#else
|
||||||
struct ucred creds = {};
|
struct ucred creds = {};
|
||||||
socklen_t creds_size = sizeof(creds);
|
socklen_t creds_size = sizeof(creds);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef AK_OS_MACOS
|
||||||
|
if (getsockopt(fd(), SOL_LOCAL, LOCAL_PEERPID, &pid, &pid_size) < 0) {
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
if (getsockopt(fd(), SOL_LOCAL, LOCAL_PEERCRED, &creds, &creds_size) < 0) {
|
||||||
|
#else
|
||||||
if (getsockopt(fd(), SOL_SOCKET, SO_PEERCRED, &creds, &creds_size) < 0) {
|
if (getsockopt(fd(), SOL_SOCKET, SO_PEERCRED, &creds, &creds_size) < 0) {
|
||||||
|
#endif
|
||||||
dbgln("LocalSocket: getsockopt failed, {}", strerror(errno));
|
dbgln("LocalSocket: getsockopt failed, {}", strerror(errno));
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AK_OS_MACOS
|
||||||
|
return pid;
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
return creds.cr_pid;
|
||||||
|
#else
|
||||||
return creds.pid;
|
return creds.pid;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue