NuProcess icon indicating copy to clipboard operation
NuProcess copied to clipboard

FreeBSD Support - Fix syscall(SYS__pthread_chdir) failed to set current directory

Open fronald opened this issue 2 years ago • 3 comments

Hello guys!

I am a developer and co-founder of Wiselabs Software in Brazil. We have some mission-critical systems that we chose to migrate to FreeBSD. In some of these systems we use NuProcess, and in the quality assurance process we found the following problem:

"syscall(SYS__pthread_chdir) failed to set current directory"

We also found a bug with the order in the process registration call (Kevent).

We chose to contribute to the project and resolve this bug. I hope it will be useful to you and other users.

Thank you so much for this wonderful library.

fronald avatar Jun 10 '22 19:06 fronald

We apologize for not having noticed that there was already another PR by jasonkafer. Feel free to decline ours. Or if you prefer, we can make the changes you need.

Thanks.

fronald avatar Jun 10 '22 19:06 fronald

Sorry for the very long delay in responding to this pull request. As was explained (by a helpful developer) on pull request #109, the change here sets the syscall to chdir, which changes the working directory for the entire process, not pthread_chdir, which changes it for the current thread. That aspect of this change won't be accepted, because using chdir has a number of issues (see this comment for details).

Adding ext to kevent may be compatible with the FreeBSD variant you're using, but is not compatible with macOS; ext is part of a separate kevent64_s struct instead (per man kqueue). We'd need some other way to handle that field to avoid memory offset issues on macOS.

I'm interested in the "bug with the order in the process registration call". Can you link me to some documentation or other code that explains why the existing order is wrong, and why the new order proposed here is correct?

bturner avatar May 05 '24 05:05 bturner

No problem. You can close this PR. We have been using this altered version for 2 years in a high-criticality production system, and there are no issues on FreeBSD. Forgive my English, but when I referred to the order, I was talking about the "getFieldOrder" field. So, the problem is basically that on FreeBSD, the "ext" field was missing. We will continue applying this patch when we update the NuProcess version to support our clusters. Thank you, and now I apologize for the delay.

fronald avatar Aug 01 '24 16:08 fronald