Blame posix/test-vfork.c

Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <error.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <sys/wait.h>
Packit 6c4009
Packit 6c4009
void __attribute_noinline__ noop (void);
Packit 6c4009
Packit 6c4009
#define NR	2	/* Exit code of the child.  */
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (void)
Packit 6c4009
{
Packit 6c4009
  pid_t pid;
Packit 6c4009
  int status;
Packit 6c4009
Packit 6c4009
  printf ("Before vfork\n");
Packit 6c4009
  fflush (stdout);
Packit 6c4009
  pid = vfork ();
Packit 6c4009
  if (pid == 0)
Packit 6c4009
    {
Packit 6c4009
      /* This will clobber the return pc from vfork in the parent on
Packit 6c4009
	 machines where it is stored on the stack, if vfork wasn't
Packit 6c4009
	 implemented correctly, */
Packit 6c4009
      noop ();
Packit 6c4009
      _exit (NR);
Packit 6c4009
    }
Packit 6c4009
  else if (pid < 0)
Packit 6c4009
    error (1, errno, "vfork");
Packit 6c4009
  printf ("After vfork (parent)\n");
Packit 6c4009
  if (waitpid (0, &status, 0) != pid
Packit 6c4009
      || !WIFEXITED (status) || WEXITSTATUS (status) != NR)
Packit 6c4009
    exit (1);
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
noop (void)
Packit 6c4009
{
Packit 6c4009
}