- while (waitpid(pid, &status, 0) != pid);
- if (status == 0) *fd = Uopen(buffer, O_APPEND|O_WRONLY, LOG_MODE);
+ if (pid > 0)
+ {
+ while (waitpid(pid, &status, 0) != pid);
+ if (status == 0) *fd = Uopen(buffer, O_APPEND|O_WRONLY, LOG_MODE);
+ }
+
+ /* If we failed to create a subprocess, we are in a bad way. We fall through
+ with *fd still < 0, and errno set, letting the code below handle the error. */