Skip to content
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

Fix FreeBSD build failures. Update tests for FreeBSD #92

Merged
merged 3 commits into from
Sep 4, 2024

Conversation

Thefrank
Copy link
Contributor

@Thefrank Thefrank commented Mar 2, 2023

Fix FreeBSD build failures. Update tests for FreeBSD

Changes

  • src/libpsl-native/CMakeLists.txt -> add CMake case for FreeBSD
  • src/libpsl-native/src/getcurrentthreadid.cpp -> add FreeBSD case
  • src/libpsl-native/src/getppid.cpp -> rework function, add case for FreeBSD
  • src/libpsl-native/src/getuserfrompid.cpp -> fix FreeBSD build failure from missing header
  • src/libpsl-native/test/ -> add FreeBSD to Apple cases. Apple and FreeBSD use the same parameters for stat

There are still two test failures related to GetDeviceID. FreeBSD returns a nonsensically high number for /usr/bin/stat -f %d /

Ubuntu 20.04:

frank@buildbot:~$ /usr/bin/stat -c %d /
64768

FreeBSD 13.1:

root@freebsd:~ # /usr/bin/stat -f %d /
2870232080986416670

Reasoning

Current FreeBSD builds fail. This PR resolves it and adds supporting tests

@Thefrank
Copy link
Contributor Author

Thefrank commented Mar 3, 2023

@microsoft-github-policy-service agree

@Thefrank
Copy link
Contributor Author

Thefrank commented Aug 5, 2023

Not sure who I should get code review from / who has write access so I am guessing based on recent PR merges

PTAL @adityapatwardhan

@Thefrank
Copy link
Contributor Author

If there is nothing else, then this is ready to merge

@shanselman
Copy link

@SteveL-MSFT this is the last one I think that's needed for dotnet/runtime#14537 upstream

@@ -9,6 +9,8 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
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")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl")
Copy link

Choose a reason for hiding this comment

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

It seems strange to pass -Wl with no arg. Of course the oddity was just duplicated from the Darwin case (where it exists in the first public version of this file).

It seems to me we ought to just mimic the Linux behaviour here, e.g. make the existing case above if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found it unusual too, but opted to include it as I assumed if it was important enough for "Darwin" to have it then so should "FreeBSD". I will go ahead and add "FreeBSD" to the "Linux" case as suggested. Thanks!

@@ -17,6 +21,9 @@ pid_t GetCurrentThreadId()
uint64_t tid64;
pthread_threadid_np(NULL, &tid64);
tid = (pid_t)tid64;
#elif defined(__FreeBSD__)
tid = pthread_getthreadid_np();
return (int)tid;
Copy link

Choose a reason for hiding this comment

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

This cast is superfluous - this function returns pid_t, which is the type of tid. Probably want in the line above tid = (pid_t)pthread_getthreadid_np();, or just avoid explicit casts altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one...I tried my best here to follow what is done under dotNET for pthread_getthreadid_np() but found it inconsistent. I can make changes both to this PR and open PRs in runtime to correct the usage it in order to avoid any information loss due to casting.

@@ -31,7 +31,7 @@
//!
pid_t GetPPid(pid_t pid)
{

#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?

@Thefrank
Copy link
Contributor Author

Thefrank commented Jul 2, 2024

What else is needed to get this merged?

Any feedback would be great!

@adityapatwardhan
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@adityapatwardhan adityapatwardhan merged commit 482c219 into PowerShell:master Sep 4, 2024
10 checks passed
@adityapatwardhan
Copy link
Member

@Thefrank thank you for your contribution!

@Thefrank Thefrank deleted the freebsd branch November 29, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants