posix_spawn(): errno in older glibc versions

Felipe Gasper felipe@felipegasper.com
Sun Mar 3 23:01:00 GMT 2019


Hi all,

	I’ve got an application that runs posix_spawn() on CentOS 6 (glibc 2.12) and CentOS 7 (glibc 2.17).

	In these older posix_spawn() implementations, the underlying clone() is reported to have succeeded, and only an exit status is reported. This makes it impossible to determine the errno value of a failed exec() in the child process.

	On my Ubuntu box (glibc 2.28), though, I notice that posix_spawn() indicates failure, with errno set to whatever failure exec() reported.

INQUIRY #1:
	I’m curious what allows the newer posix_spawn() to report the exec()’s errno in this case. From my reading of vfork(2)’s man page (“Standard Description”), any behavior that would indicate the exec’s errno back to the parent process seems to be undefined behavior:

-----
the behavior is undefined if the process created by vfork()
either  modifies  any  data other than a variable of type pid_t used to
store the return value from vfork(), or returns from  the  function  in
which  vfork()  was called, or calls any other function before success-
fully calling _exit(2) or one of the exec(3) family of functions.
-----

How, then, does the new posix_spawn() pass the child’s errno back to the parent? Does it violate the above--assumedly with some assurance that what it’s doing is, in fact, safe?


INQUIRY #2:
	Putting questions of distribution aside, how feasible would it be to patch the older glibc versions (2.12 and 2.17) to report the child’s errno to the parent?


	Thank you!


-Felipe Gasper
Mississauga, Ontario


More information about the Libc-help mailing list