posix_spawn is supposed to return a value indicating an error when it fails.
The specification for it is here:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html
>From the spec: Otherwise, no child process shall be created, the value
stored into the variable pointed to by a non-NULL pid is unspecified,
and *an error number shall be returned as the function return value*
to indicate the error.
However, OpenBSD is returning 0 (success) instead of some kind of
indication of error (such as 2 for ENOENT).
Test program:
-------------------------
#include <stdio.h>
#include <spawn.h>
int main()
{
extern char **environ;
char *argv[] = { "/bin/blah_blah-blah", 0 };
pid_t pid = -1;
int ret = posix_spawn(&pid, argv[0], 0, 0, argv, environ);
printf("ret: %d\npid: %ld\n", ret, (long)pid);
return(0);
}
-------------------------
"/bin/blah_blah-blah" doesn't exist, so it should not successfully spawn.
A freshly installed OpenBSD 5.7 for this program is returning:
ret: 0
pid: 24118
FreeBSD, DragonFlyBSD, NetBSD, and musl-libc all handle this correctly.
With them:
ret: 2
pid: -1 (some will put a different value here, which is allowed by the standard)
On a side note, a similar problem exists in GLIBC:
https://sourceware.org/bugzilla/show_bug.cgi?id=18433