| 1 |
/* COVERAGE: wait waitpid waitid */ |
| 2 |
|
| 3 |
#define _GNU_SOURCE |
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
#include <unistd.h> |
| 7 |
#include <sys/types.h> |
| 8 |
#include <sys/time.h> |
| 9 |
#include <sys/resource.h> |
| 10 |
#include <sys/wait.h> |
| 11 |
#include <sys/syscall.h> |
| 12 |
|
| 13 |
// To test for glibc support for waitid: |
| 14 |
// |
| 15 |
// _SVID_SOURCE || _XOPEN_SOURCE >= 500 || |
| 16 |
// _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED |
| 17 |
// || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L |
| 18 |
|
| 19 |
#define GLIBC_SUPPORT \ |
| 20 |
(_SVID_SOURCE || _XOPEN_SOURCE >= 500 || \ |
| 21 |
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED \ |
| 22 |
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L) |
| 23 |
|
| 24 |
int |
| 25 |
main() |
| 26 |
{ |
| 27 |
pid_t child; |
| 28 |
int status; |
| 29 |
#ifdef GLIBC_SUPPORT |
| 30 |
siginfo_t info; |
| 31 |
#endif |
| 32 |
|
| 33 |
/* wait() can be implemented by: |
| 34 |
* |
| 35 |
* waitpid(-1, &status 0); |
| 36 |
* |
| 37 |
* or: |
| 38 |
* |
| 39 |
* wait4(-1, &status, 0, NULL); |
| 40 |
* |
| 41 |
* So, on many platforms it doesn't really exist. |
| 42 |
*/ |
| 43 |
#ifdef __NR_wait |
| 44 |
child = fork(); |
| 45 |
#if !defined(__ia64__) |
| 46 |
// Sometimes glibc substitutes a clone() call for a fork() |
| 47 |
// call (verified with strace). |
| 48 |
//staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN |
| 49 |
#else |
| 50 |
// On RHEL5 ia64, fork() gets turned into clone2(). |
| 51 |
//staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN |
| 52 |
#endif |
| 53 |
if (!child) { |
| 54 |
sleep(1); |
| 55 |
exit(0); |
| 56 |
} |
| 57 |
wait(&status); |
| 58 |
//staptest// wait (XXXX) = NNNN |
| 59 |
|
| 60 |
/* Limit testing. */ |
| 61 |
wait((int *)-1); |
| 62 |
#ifdef __s390__ |
| 63 |
//staptest// wait (0x[7]?[f]+) = -NNNN |
| 64 |
#else |
| 65 |
//staptest// wait (0x[f]+) = -NNNN |
| 66 |
#endif |
| 67 |
#endif |
| 68 |
|
| 69 |
/* waitpid() can be implemented by: |
| 70 |
* |
| 71 |
* wait4(-1, &status, 0, NULL); |
| 72 |
* |
| 73 |
* So, on many platforms it doesn't really exist. |
| 74 |
*/ |
| 75 |
#ifdef __NR_waitpid |
| 76 |
child = fork(); |
| 77 |
#if !defined(__ia64__) |
| 78 |
// Sometimes glibc substitutes a clone() call for a fork() |
| 79 |
// call (verified with strace). |
| 80 |
//staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN |
| 81 |
#else |
| 82 |
// On RHEL5 ia64, fork() gets turned into clone2(). |
| 83 |
//staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN |
| 84 |
#endif |
| 85 |
if (!child) { |
| 86 |
sleep(1); |
| 87 |
exit(0); |
| 88 |
} |
| 89 |
waitpid(-1, &status, 0); |
| 90 |
//staptest// waitpid (-1, XXXX, 0x0) = NNNN |
| 91 |
|
| 92 |
/* Limit testing. */ |
| 93 |
waitpid(-1, (int *)-1, WNOHANG); |
| 94 |
#ifdef __s390__ |
| 95 |
//staptest// waitpid (-1, 0x[7]?[f]+, WNOHANG) = NNNN |
| 96 |
#else |
| 97 |
//staptest// waitpid (-1, 0x[f]+, WNOHANG) = NNNN |
| 98 |
#endif |
| 99 |
|
| 100 |
waitpid(-1, &status, -1); |
| 101 |
//staptest// waitpid (-1, XXXX, W[^ ]+|XXXX) = -NNNN |
| 102 |
#endif |
| 103 |
|
| 104 |
#ifdef GLIBC_SUPPORT |
| 105 |
child = fork(); |
| 106 |
#if !defined(__ia64__) |
| 107 |
// Sometimes glibc substitutes a clone() call for a fork() |
| 108 |
// call (verified with strace). |
| 109 |
//staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN |
| 110 |
#else |
| 111 |
// On RHEL5 ia64, fork() gets turned into clone2(). |
| 112 |
//staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN |
| 113 |
#endif |
| 114 |
if (!child) { |
| 115 |
sleep(1); |
| 116 |
exit(0); |
| 117 |
} |
| 118 |
waitid(P_ALL, 0, &info, WEXITED); |
| 119 |
//staptest// waitid (P_ALL, 0, XXXX, WEXITED, 0x0) = 0 |
| 120 |
|
| 121 |
/* Limit testing. */ |
| 122 |
waitid(-1, 0, &info, 0); |
| 123 |
//staptest// waitid (0xffffffff, 0, XXXX, 0x0, 0x0) = NNNN |
| 124 |
|
| 125 |
waitid(P_ALL, -1, &info, 0); |
| 126 |
//staptest// waitid (P_ALL, -1, XXXX, 0x0, 0x0) = NNNN |
| 127 |
|
| 128 |
waitid(P_ALL, 0, (siginfo_t *)-1, 0); |
| 129 |
#ifdef __s390__ |
| 130 |
//staptest// waitid (P_ALL, 0, 0x[7]?[f]+, 0x0, 0x0) = NNNN |
| 131 |
#else |
| 132 |
//staptest// waitid (P_ALL, 0, 0x[f]+, 0x0, 0x0) = NNNN |
| 133 |
#endif |
| 134 |
|
| 135 |
waitid(P_ALL, 0, &info, -1); |
| 136 |
//staptest// waitid (P_ALL, 0, XXXX, W[^ ]+|XXXX, 0x0) = NNNN |
| 137 |
#endif |
| 138 |
exit(0); |
| 139 |
} |