mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +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
Notes:
sideshowbarker
2024-07-18 00:57:54 +09:00
Author: https://github.com/qiu-x 🔰 Commit: https://github.com/SerenityOS/serenity/commit/c0a7e0ad23e Pull-request: https://github.com/SerenityOS/serenity/pull/10928 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/kleinesfilmroellchen ✅
1 changed files with 18 additions and 7 deletions
|
@ -11,6 +11,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#if defined(__FreeBSD__)
|
||||
# include <sys/ucred.h>
|
||||
#endif
|
||||
|
||||
#ifndef SOCK_NONBLOCK
|
||||
# include <sys/ioctl.h>
|
||||
|
@ -58,22 +61,30 @@ pid_t LocalSocket::peer_pid() const
|
|||
#ifdef AK_OS_MACOS
|
||||
pid_t pid;
|
||||
socklen_t pid_size = sizeof(pid);
|
||||
|
||||
if (getsockopt(fd(), SOL_LOCAL, LOCAL_PEERPID, &pid, &pid_size) < 0) {
|
||||
dbgln("LocalSocket: getsockopt failed, {}", strerror(errno));
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
return pid;
|
||||
#elif defined(__FreeBSD__)
|
||||
struct xucred creds = {};
|
||||
socklen_t creds_size = sizeof(creds);
|
||||
#else
|
||||
struct ucred 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) {
|
||||
#endif
|
||||
dbgln("LocalSocket: getsockopt failed, {}", strerror(errno));
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
#ifdef AK_OS_MACOS
|
||||
return pid;
|
||||
#elif defined(__FreeBSD__)
|
||||
return creds.cr_pid;
|
||||
#else
|
||||
return creds.pid;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue