Skip to content

Commit 0f83337

Browse files
mateusrodriguesUser Mateus
authored and
User Mateus
committed
Fix FreeBSD libpsl tests
1 parent c54bdb4 commit 0f83337

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libpsl-native/src/getuserfrompid.cpp

Lines changed: 20 additions & 0 deletions
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

@@ -45,6 +49,22 @@ char* GetUserFromPid(pid_t pid)
4549

4650
return GetPwUid(oldp.kp_eproc.e_ucred.cr_uid);
4751

52+
#elif defined(__FreeBSD__)
53+
54+
// Get effective owner of pid from sysctl
55+
struct kinfo_proc oldp;
56+
size_t oldlenp = sizeof(oldp);
57+
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
58+
u_int namelen = sizeof(name)/sizeof(int);
59+
60+
int ret = sysctl(name, namelen, &oldp, &oldlenp, NULL, 0);
61+
if (ret != 0 || oldlenp == 0)
62+
{
63+
return NULL;
64+
}
65+
66+
return GetPwUid(oldp.ki_uid);
67+
4868
#else
4969

5070
return NULL;

0 commit comments

Comments
 (0)