8000 Fix FreeBSD build failures. Update tests for FreeBSD by Thefrank · Pull Request #92 · PowerShell/PowerShell-Native · GitHub
[go: up one dir, main page]

Skip to content

Fix FreeBSD build failures. Update tests for FreeBSD #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 4, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/libpsl-native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(PSL-NATIVE)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2")

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR "FreeBSD")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro,-z,now")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl")
Expand Down
6 changes: 6 additions & 0 deletions src/libpsl-native/src/getcurrentthreadid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <sys/syscall.h>
#include <pthread.h>

#if __FreeBSD__
#include <pthread_np.h>
#endif

pid_t GetCurrentThreadId()
{
pid_t tid = 0;
Expand All @@ -17,6 +21,8 @@ pid_t GetCurrentThreadId()
uint64_t tid64;
pthread_threadid_np(NULL, &tid64);
tid = (pid_t)tid64;
#elif defined(__FreeBSD__)
tid = pthread_getthreadid_np();
#endif
return tid;
}
17 changes: 11 additions & 6 deletions src/libpsl-native/src/getppid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include <sys/sysctl.h>
#endif

#if __FreeBSD__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

//! @brief GetPPid returns the parent process id for a process
//!
//! GetPPid
Expand All @@ -26,20 +31,20 @@
//!
pid_t GetPPid(pid_t pid)
{

#if defined(__APPLE__) && defined(__MACH__)

#if defined (__APPLE__) && defined(__MACH__) || defined(__FreeBSD__)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roll this commit into previous?

const pid_t PIDUnknown = UINT_MAX;
struct kinfo_proc info;
size_t length = sizeof(struct kinfo_proc);
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
if (sysctl(mib, 4, &info, &length, NULL, 0) < 0)
return PIDUnknown;
if (length == 0)
return PIDUnknown;

#if defined (__APPLE__) && defined(__MACH__)
return info.kp_eproc.e_ppid;

#elif defined(__FreeBSD__)
return info.ki_ppid;
#endif
#else

return UINT_MAX;
Expand Down
1 change: 1 addition & 0 deletions src/libpsl-native/src/getuserfrompid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#if __FreeBSD__
#include <sys/user.h>
#include <sys/sysctl.h>
#endif

char* GetUserFromPid(pid_t pid)
Expand Down
22 changes: 11 additions & 11 deletions src/libpsl-native/test/test-getcommonlstat.cpp
8000
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST(GetCommonLStat, GetOwnerIdOfRoot)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %u /", "r");
#else
p = popen("/usr/bin/stat -c %u /", "r");
Expand All @@ -56,7 +56,7 @@ TEST(GetCommonLStat, GetGroupId)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %g /", "r");
#else
p = popen("/usr/bin/stat -c %g /", "r");
Expand All @@ -73,7 +73,7 @@ TEST(GetCommonLStat, GetInodeNumber)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %i /", "r");
#else
p = popen("/usr/bin/stat -c %i /", "r");
Expand All @@ -90,7 +90,7 @@ TEST(GetCommonLStat, GetSize)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %z /", "r");
#else
p = popen("/usr/bin/stat -c %s /", "r");
Expand All @@ -107,7 +107,7 @@ TEST(GetCommonLStat, GetBlockSize)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %k /", "r");
#else
p = popen("/usr/bin/stat -c %o /", "r");
Expand All @@ -124,7 +124,7 @@ TEST(GetCommonLStat, GetBlockCount)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %b /", "r");
#else
p = popen("/usr/bin/stat -c %b /", "r");
Expand All @@ -141,7 +141,7 @@ TEST(GetCommonLStat, GetLinkCount)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %l /", "r");
#else
p = popen("/usr/bin/stat -c %h /", "r");
Expand All @@ -158,7 +158,7 @@ TEST(GetCommonLStat, GetDeviceId)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %d /", "r");
#else
p = popen("/usr/bin/stat -c %d /", "r");
Expand All @@ -175,7 +175,7 @@ TEST(GetCommonLStat, GetATime)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %a /", "r");
#else
p = popen("/usr/bin/stat -c %X /", "r");
Expand All @@ -192,7 +192,7 @@ TEST(GetCommonLStat, GetMTime)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %m /", "r");
#else
p = popen("/usr/bin/stat -c %Y /", "r");
Expand All @@ -209,7 +209,7 @@ TEST(GetCommonLStat, GetCTime)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %c /", "r");
#else
p = popen("/usr/bin/stat -c %Z /", "r");
Expand Down
24 changes: 12 additions & 12 deletions src/libpsl-native/test/test-getcommonstat.cpp
< 5081 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST(GetCommonStat, GetOwnerIdOfRoot)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %u /", "r");
#else
p = popen("/usr/bin/stat -c %u /", "r");
Expand All @@ -58,7 +58,7 @@ TEST(GetCommonStat, GetGroupId)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %g /", "r");
#else
p = popen("/usr/bin/stat -c %g /", "r");
Expand All @@ -75,7 +75,7 @@ TEST(GetCommonStat, GetInodeNumber)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %i /", "r");
#else
p = popen("/usr/bin/stat -c %i /", "r");
Expand All @@ -93,7 +93,7 @@ TEST(GetCommonStat, GetMode)
FILE *p;
CommonStat cs;
unsigned int mode = -1;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %p /", "r");
int result = fscanf(p, "%o", &mode);
#else
Expand All @@ -110,7 +110,7 @@ TEST(GetCommonStat, GetSize)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %z /", "r");
#else
p = popen("/usr/bin/stat -c %s /", "r");
Expand All @@ -127,7 +127,7 @@ TEST(GetCommonStat, GetBlockSize)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %k /", "r");
#else
p = popen("/usr/bin/stat -c %o /", "r");
Expand All @@ -144,7 +144,7 @@ TEST(GetCommonStat, GetBlockCount)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %b /", "r");
#else
p = popen("/usr/bin/stat -c %b /", "r");
Expand All @@ -161,7 +161,7 @@ TEST(GetCommonStat, GetLinkCount)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %l /", "r");
#else
p = popen("/usr/bin/stat -c %h /", "r");
Expand All @@ -178,7 +178,7 @@ TEST(GetCommonStat, GetDeviceId)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %d /", "r");
#else
p = popen("/usr/bin/stat -c %d /", "r");
Expand All @@ -195,7 +195,7 @@ TEST(GetCommonStat, GetATime)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %a /", "r");
#else
p = popen("/usr/bin/stat -c %X /", "r");
Expand All @@ -212,7 +212,7 @@ TEST(GetCommonStat, GetMTime)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %m /", "r");
#else
p = popen("/usr/bin/stat -c %Y /", "r");
Expand All @@ -229,7 +229,7 @@ TEST(GetCommonStat, GetCTime)
{
FILE *p;
CommonStat cs;
#if defined (__APPLE__)
#if defined (__APPLE__) || defined(__FreeBSD__)
p = popen("/usr/bin/stat -f %c /", "r");
#else
p = popen("/usr/bin/stat -c %Z /", "r");
Expand Down
0