Skip to content

Commit 6de9504

Browse files
mateusrodriguesadityapatwardhan
authored andcommitted
Fix libpsl-native to build and pass tests on FreeBSD (#2)
1 parent c54bdb4 commit 6de9504

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/libpsl-native/src/getuserfrompid.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <sys/sysctl.h>
1616
#endif
1717

18+
#if __FreeBSD__
19+
#include <sys/user.h>
20+
#endif
21+
1822
char* GetUserFromPid(pid_t pid)
1923
{
2024

@@ -28,7 +32,7 @@ char* GetUserFromPid(pid_t pid)
2832

2933
return GetFileOwner(path.c_str());
3034

31-
#elif defined(__APPLE__) && defined(__MACH__)
35+
#elif (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
3236

3337
// Get effective owner of pid from sysctl
3438
struct kinfo_proc oldp;
@@ -43,7 +47,11 @@ char* GetUserFromPid(pid_t pid)
4347
return NULL;
4448
}
4549

50+
#if defined(__FreeBSD__)
51+
return GetPwUid(oldp.ki_uid);
52+
#else
4653
return GetPwUid(oldp.kp_eproc.e_ucred.cr_uid);
54+
#endif
4755

4856
#else
4957

0 commit comments

Comments
 (0)