Re: [PATCH v4 09/12] unix-socket: disallow chdir() when creating unix domain sockets
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 5, 2021, 17:53 UTC
- Message-ID
- <xmqqczwdbi80.fsf@gitster.c.googlers.com>
- In-Reply-To
- <449a73be-52e3-8363-b771-959f8114e3a0@jeffhostetler.com>
Jeff Hostetler <git@jeffhostetler.com> writes:
Show 9 quoted lines
> The original problem was that chdir() is not safe in a multi-threaded > process because one thread calling chdir() will affect any concurrent > file operations (open(), mkdir(), etc.) that use relative paths. > > I think Adding a fork() at this layer would just create new types of > problems. For example, if another thread was concurrently writing to > a socket while we were setting up this new socket, we would suddenly > have 1 thread in each process now writing to that socket and the > receiver would get a mixture of output from both processes. Right?
cf. https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html
The fork() function shall create a new process. The new process (child process) shall be an exact copy of the calling process (parent process) except as detailed below:
...
* A process shall be created with a single thread. If a multi-threaded process calls fork(), the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called.
So, probably not.