File: wait.c

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (139 lines) | stat: -rw-r--r-- 3,570 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* COVERAGE: wait waitpid waitid */

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/syscall.h>

// To test for glibc support for waitid:
//
//   _SVID_SOURCE || _XOPEN_SOURCE >= 500 ||
//   _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
//   || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L

#define GLIBC_SUPPORT \
    (_SVID_SOURCE || _XOPEN_SOURCE >= 500 ||  \
     _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED \
     || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L)

int
main()
{
    pid_t child;
    int status;
#ifdef GLIBC_SUPPORT
    siginfo_t info;
#endif

    /* wait() can be implemented by:
     *
     *   waitpid(-1, &status 0);
     *
     * or:
     *
     *   wait4(-1, &status, 0, NULL);
     *
     * So, on many platforms it doesn't really exist.
     */
#ifdef __NR_wait
    child = fork();
#if !defined(__ia64__)
    // Sometimes glibc substitutes a clone() call for a fork()
    // call (verified with strace).
    //staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN
#else
    // On RHEL5 ia64, fork() gets turned into clone2().
    //staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN
#endif
    if (!child) {
	sleep(1);
	exit(0);
    }
    wait(&status);
    //staptest// wait (XXXX) = NNNN

    /* Limit testing. */
    wait((int *)-1);
#ifdef __s390__
    //staptest// wait (0x[7]?[f]+) = -NNNN
#else
    //staptest// wait (0x[f]+) = -NNNN
#endif
#endif

    /* waitpid() can be implemented by:
     *
     *   wait4(-1, &status, 0, NULL);
     *
     * So, on many platforms it doesn't really exist.
     */
#ifdef __NR_waitpid
    child = fork();
#if !defined(__ia64__)
    // Sometimes glibc substitutes a clone() call for a fork()
    // call (verified with strace).
    //staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN
#else
    // On RHEL5 ia64, fork() gets turned into clone2().
    //staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN
#endif
    if (!child) {
	sleep(1);
	exit(0);
    }
    waitpid(-1, &status, 0);
    //staptest// waitpid (-1, XXXX, 0x0) = NNNN

    /* Limit testing. */
    waitpid(-1, (int *)-1, WNOHANG);
#ifdef __s390__
    //staptest// waitpid (-1, 0x[7]?[f]+, WNOHANG) = NNNN
#else
    //staptest// waitpid (-1, 0x[f]+, WNOHANG) = NNNN
#endif

    waitpid(-1, &status, -1);
    //staptest// waitpid (-1, XXXX, W[^ ]+|XXXX) = -NNNN
#endif

#ifdef GLIBC_SUPPORT
    child = fork();
#if !defined(__ia64__)
    // Sometimes glibc substitutes a clone() call for a fork()
    // call (verified with strace).
    //staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN
#else
    // On RHEL5 ia64, fork() gets turned into clone2().
    //staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN
#endif
    if (!child) {
	sleep(1);
	exit(0);
    }
    waitid(P_ALL, 0, &info, WEXITED);
    //staptest// waitid (P_ALL, 0, XXXX, WEXITED, 0x0) = 0

    /* Limit testing. */
    waitid(-1, 0, &info, 0);
    //staptest// waitid (0xffffffff, 0, XXXX, 0x0, 0x0) = NNNN

    waitid(P_ALL, -1, &info, 0);
    //staptest// waitid (P_ALL, -1, XXXX, 0x0, 0x0) = NNNN

    waitid(P_ALL, 0, (siginfo_t *)-1, 0);
#ifdef __s390__
    //staptest// waitid (P_ALL, 0, 0x[7]?[f]+, 0x0, 0x0) = NNNN
#else
    //staptest// waitid (P_ALL, 0, 0x[f]+, 0x0, 0x0) = NNNN
#endif

    waitid(P_ALL, 0, &info, -1);
    //staptest// waitid (P_ALL, 0, XXXX, W[^ ]+|XXXX, 0x0) = NNNN
#endif
    exit(0);
}