| 1 |
/* COVERAGE: wait4 */ |
| 2 |
|
| 3 |
#include <stdio.h> |
| 4 |
#include <stdlib.h> |
| 5 |
#include <unistd.h> |
| 6 |
#include <sys/types.h> |
| 7 |
#include <sys/time.h> |
| 8 |
#include <sys/resource.h> |
| 9 |
#include <sys/wait.h> |
| 10 |
|
| 11 |
static long get_pid_max(void) |
| 12 |
{ |
| 13 |
long pid_max = 32768; /* default */ |
| 14 |
|
| 15 |
FILE *fp = fopen("/proc/sys/kernel/pid_max", "r"); |
| 16 |
if (fp) { |
| 17 |
fscanf(fp, "%ld", &pid_max); |
| 18 |
fclose(fp); |
| 19 |
} |
| 20 |
return pid_max; |
| 21 |
} |
| 22 |
|
| 23 |
int |
| 24 |
main() |
| 25 |
{ |
| 26 |
pid_t epid = get_pid_max() + 1; |
| 27 |
pid_t child; |
| 28 |
|
| 29 |
wait4(epid, NULL, 0, NULL); |
| 30 |
//staptest// wait4 (NNNN, 0x0, 0x0, 0x0) = -NNNN (ECHILD) |
| 31 |
|
| 32 |
wait4(-1, NULL, 0, NULL); |
| 33 |
//staptest// wait4 (-1, 0x0, 0x0, 0x0) = -NNNN (ECHILD) |
| 34 |
|
| 35 |
child = fork(); |
| 36 |
#if !defined(__ia64__) |
| 37 |
// Sometimes glibc substitutes a clone() call for a fork() |
| 38 |
// call (verified with strace). |
| 39 |
//staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN |
| 40 |
#else |
| 41 |
// On RHEL5 ia64, fork() gets turned into clone2(). |
| 42 |
//staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN |
| 43 |
#endif |
| 44 |
if (!child) { |
| 45 |
int i = 0xfffff; |
| 46 |
while (i > 0) i--; |
| 47 |
exit(0); |
| 48 |
} |
| 49 |
wait4(child, (int *)-1, 0, NULL); |
| 50 |
#ifdef __s390__ |
| 51 |
//staptest// wait4 (NNNN, 0x[7]?[f]+, 0x0, 0x0) = -NNNN (EFAULT) |
| 52 |
#else |
| 53 |
//staptest// wait4 (NNNN, 0x[f]+, 0x0, 0x0) = -NNNN (EFAULT) |
| 54 |
#endif |
| 55 |
|
| 56 |
// Just in case the failing wait4() call above didn't clean up... |
| 57 |
wait4(child, 0, 0, NULL); |
| 58 |
//staptest// wait4 (NNNN, 0x0, 0x0, 0x0) |
| 59 |
|
| 60 |
child = fork(); |
| 61 |
#if !defined(__ia64__) |
| 62 |
// Sometimes glibc substitutes a clone() call for a fork() |
| 63 |
// call (verified with strace). |
| 64 |
//staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN |
| 65 |
#else |
| 66 |
// On RHEL5 ia64, fork() gets turned into clone2(). |
| 67 |
//staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN |
| 68 |
#endif |
| 69 |
if (!child) { |
| 70 |
int i = 0xfffff; |
| 71 |
while (i > 0) i--; |
| 72 |
exit(0); |
| 73 |
} |
| 74 |
|
| 75 |
// A -1 options value ends up looking like all options are set |
| 76 |
// (plus a few extra). |
| 77 |
wait4(child, NULL, -1, NULL); |
| 78 |
//staptest// wait4 (NNNN, 0x0, .+|XXXX, 0x0) = -NNNN (EINVAL) |
| 79 |
|
| 80 |
// Just in case the failing wait4() call above didn't clean up... |
| 81 |
wait4(child, 0, 0, NULL); |
| 82 |
//staptest// wait4 (NNNN, 0x0, 0x0, 0x0) |
| 83 |
|
| 84 |
child = fork(); |
| 85 |
#if !defined(__ia64__) |
| 86 |
// Sometimes glibc substitutes a clone() call for a fork() |
| 87 |
// call (verified with strace). |
| 88 |
//staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN |
| 89 |
#else |
| 90 |
// On RHEL5 ia64, fork() gets turned into clone2(). |
| 91 |
//staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN |
| 92 |
#endif |
| 93 |
if (!child) { |
| 94 |
int i = 0xfffff; |
| 95 |
while (i > 0) i--; |
| 96 |
exit(0); |
| 97 |
} |
| 98 |
|
| 99 |
// The following SEGVs if compiled as a 32-on-64 bit binary on x86_64 |
| 100 |
#if __WORDSIZE == 64 |
| 101 |
wait4(child, NULL, 0, (struct rusage *)-1); |
| 102 |
#ifdef __s390__ |
| 103 |
//staptest// wait4 (NNNN, 0x0, 0x0, 0x[7]?[f]+) = -NNNN (EFAULT) |
| 104 |
#else |
| 105 |
//staptest// wait4 (NNNN, 0x0, 0x0, 0x[f]+) = -NNNN (EFAULT) |
| 106 |
#endif |
| 107 |
#endif |
| 108 |
|
| 109 |
// Just in case the failing wait4() call above didn't clean up... |
| 110 |
wait4(child, 0, 0, NULL); |
| 111 |
//staptest// wait4 (NNNN, 0x0, 0x0, 0x0) |
| 112 |
|
| 113 |
exit(0); |
| 114 |
} |