1*8a272653SPeter Holm#!/bin/sh 2*8a272653SPeter Holm 3*8a272653SPeter Holm# truss / pdfork regression test. 4*8a272653SPeter Holm# Test scenario by: Ryan Stone rstone@, slightly mangled by pho@ 5*8a272653SPeter Holm 6*8a272653SPeter Holm# Interruptable hang seen: 7*8a272653SPeter Holm# $ ps -lp992 8*8a272653SPeter Holm# UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND 9*8a272653SPeter Holm# 1001 992 991 0 27 0 4168 1908 - TX+ 0 0:00.00 /tmp/pdfork -p 10*8a272653SPeter Holm# $ 11*8a272653SPeter Holm 12*8a272653SPeter Holmcat > /tmp/pdfork.c <<EOF 13*8a272653SPeter Holm#include <sys/types.h> 14*8a272653SPeter Holm#include <sys/procdesc.h> 15*8a272653SPeter Holm#include <sys/resource.h> 16*8a272653SPeter Holm#include <sys/time.h> 17*8a272653SPeter Holm#include <sys/wait.h> 18*8a272653SPeter Holm#include <err.h> 19*8a272653SPeter Holm#include <stdlib.h> 20*8a272653SPeter Holm#include <stdio.h> 21*8a272653SPeter Holm#include <string.h> 22*8a272653SPeter Holm#include <unistd.h> 23*8a272653SPeter Holm 24*8a272653SPeter Holmint 25*8a272653SPeter Holmmain(int argc, char **argv) 26*8a272653SPeter Holm{ 27*8a272653SPeter Holm pid_t pid; 28*8a272653SPeter Holm int fd; 29*8a272653SPeter Holm 30*8a272653SPeter Holm if (argc > 1 && strcmp(argv[1], "-p") == 0) { 31*8a272653SPeter Holm pid = pdfork(&fd, 0); 32*8a272653SPeter Holm } else { 33*8a272653SPeter Holm pid = fork(); 34*8a272653SPeter Holm } 35*8a272653SPeter Holm 36*8a272653SPeter Holm if (pid == 0) { 37*8a272653SPeter Holm sleep(1); 38*8a272653SPeter Holm exit(0); 39*8a272653SPeter Holm } else if (pid < 0) { 40*8a272653SPeter Holm err(1, "fork() failed"); 41*8a272653SPeter Holm } else { 42*8a272653SPeter Holm int status = 0; 43*8a272653SPeter Holm if (argc > 1 && strcmp(argv[1], "-p") != 0) { 44*8a272653SPeter Holm int error = wait4(pid, &status, WEXITED, NULL); 45*8a272653SPeter Holm if (error < 0) 46*8a272653SPeter Holm err(1, "wait4 failed"); 47*8a272653SPeter Holm } 48*8a272653SPeter Holm exit(status); 49*8a272653SPeter Holm } 50*8a272653SPeter Holm} 51*8a272653SPeter HolmEOF 52*8a272653SPeter Holmcc -o /tmp/pdfork -Wall -Wextra -O2 /tmp/pdfork.c || exit 1 53*8a272653SPeter Holm 54*8a272653SPeter Holmtimeout 20s truss -f /tmp/pdfork 2> /dev/null; s1=$? 55*8a272653SPeter Holmtimeout 20s truss -f /tmp/pdfork -p 2> /dev/null; s2=$? 56*8a272653SPeter Holm 57*8a272653SPeter Holmrm -f /tmp/pdfork /tmp/pdfork.c 58*8a272653SPeter Holmreturn $((s1 + s2)) 59