2 ms·
What posix_spawn does is something like this: posix_spawn() { ... pid_t pid = fork(); if (pid == 0) { ... } els
by klodolph 7y ago
What posix_spawn does is something like this:
posix_spawn() {
...
pid_t pid = fork();
if (pid == 0) {
...
} else if (pid > 0) {
...
if (...) {
...
return ernno_from_child;
}
...
} else {
return errno;
}
...
}
I’m just pointing out that you’re still using errno, you’ve just hidden it behind a function. All of your syscalls are still getting their results stored in errno. It’s just fork() / exec() with some extra sauce, not a syscall in itself.
I’m not trying to argue, I’m just pointing out that this is just a wrapper function on Linux anyway, and if you want to find an example of a different way to report errors from the kernel, it’s not posix_spawn().
- tyingq 7y agoPosix_spawn on Linux uses the clone() system call, and passes a pointer called args. Errors come back at args.err
- klodolph 7y agoposix_spawn() actually uses fork() internally, not clone(), as far as that distinction is possible to make. Both fork() and clone() are implemented with the same kernel entry point, which is called "clone". Here is the relevant line in glibc: https://github.com/bminor/glibc/blob/b5b7fb76e15c0db545aa11a3ce88f836e5d01a19/sysdeps/posix/spawni.c#L303 https://github.com/bminor/glibc/blob/b5b7fb76e15c0db545aa11a... Errors are returned as the function return value.
- tyingq 7y agohttps://github.com/bminor/glibc/blob/master/sysdeps/unix/sysv/linux/spawni.c#L36 https://github.com/bminor/glibc/blob/master/sysdeps/unix/sys... "The Linux implementation of posix_spawn{p} uses the clone syscall directly with CLONE_VM and CLONE_VFORK flags..." Though you're right about errno, line 305.