Proposal Details
Darwin has __pthread_chdir
and __pthread_fchdir
syscalls, wrapped (for internal use) in libpthread as pthread_chdir_np
and pthread_fchdir_np
(https://opensource.apple.com/source/libpthread/libpthread-454.80.2/src/pthread_cwd.c.auto.html), and used (as the latter) by projects such as Chromium. Documentation for the wrappers is also available in a private header file (https://opensource.apple.com/source/libpthread/libpthread-454.80.2/private/pthread/private.h.auto.html).
With runtime.{Lock,Unlock}OSThread
and those syscalls, it's possible to handle unix sockets with absolute paths longer than the maximum for a sockaddr_un
, by changing the current directory for a single thread and using a relative path, and I'm sure the ability to temporarily change directory without affecting the rest of the program can be useful in other scenarios too.
I'm opening this as a proposal because the fact that the wrappers are internal and the syscalls are double-underscored is a bit sketchy, and I'm not sure if it's ok to go:cgo_import_dynamic
the wrapper functions from libSystem.B.dylib
even though technically they're in libpthread
.
Of note is that x/sys/unix includes the SYS___PTHREAD_CHDIR
and SYS___PTHREAD_FCHDIR
constants already, but using syscall numbers is deprecated on darwin, afaict.
Comment From: ianlancetaylor
Thanks. It's not necessary to open a proposal to add simple syscall wrappers to x/sys/unix. You can just send a patch. Taking this out of the proposal process.
Comment From: gopherbot
Change https://go.dev/cl/595677 mentions this issue: unix: add PthreadChdir and PthreadFchdir on darwin