On Wed, Oct 26, 2022 at 07:20:20AM +0200, Anton Lindqvist wrote:
> On Tue, Oct 25, 2022 at 10:08:26AM -0600, Mark Kettenis wrote:
> > CVSROOT: /cvs
> > Module name: src
> > Changes by: [email protected] 2022/10/25 10:08:26
> >
> > Modified files:
> > sys/sys : siginfo.h wait.h
> > sys/kern : kern_exit.c
> >
> > Log message:
> > Implement waitid(2) which is now part of POSIX and used by mozilla.
> > This includes a change of siginfo_r which is technically an ABI break but
> > this should have no real-world impact since the members involved are
> > never touched by the kernel.
> >
> > ok millert@, deraadt@
>
> My snapshot build failed today, smells related to this as I have never
> seen this before. Will try to gather more info later today.
>
> robsd-exec: waitpid: No child processes
This program used to exit zero:
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
static int exitstatus(int);
static int waiteof(int, int);
int
main(void)
{
pid_t pid;
int pip[2];
int error, status;
if (pipe2(pip, O_NONBLOCK) == -1)
err(1, "pipe2");
pid = fork();
if (pid == -1)
err(1, "fork");
if (pid == 0) {
close(pip[0]);
if (setsid() == -1)
err(1, "setsid");
/* Signal to the parent that the process group is present. */
close(pip[1]);
_exit(0);
}
/* Wait for the process group to become present. */
close(pip[1]);
if (waiteof(pip[0], 1000)) {
warnx("process group failure");
if (waitpid(pid, &status, 0) == -1)
return 1;
return exitstatus(status);
}
close(pip[0]);
if (waitpid(-pid, &status, 0) == -1)
err(1, "waitpid");
error = exitstatus(status);
if (error)
warnx("process group exited %d", error);
return error;
}
static int
exitstatus(int status)
{
if (WIFEXITED(status))
return WEXITSTATUS(status);
if (WIFSIGNALED(status))
return 128 + WTERMSIG(status);
return 1;
}
static int
waiteof(int fd, int timoms)
{
int slpms = 100;
for (;;) {
char buf[1];
ssize_t n;
n = read(fd, buf, sizeof(buf));
if (n == -1) {
if (errno == EAGAIN) {
usleep(slpms * 1000);
timoms -= slpms;
if (timoms <= 0)
return 1;
} else {
warn("read");
return 1;
}
}
if (n == 0)
break;
}
return 0;
}