|
25 | 25 | #define PORTABLE_TAG "waitpid_portable"
|
26 | 26 | #include <log_portable.h>
|
27 | 27 |
|
| 28 | +/* |
| 29 | + * Converts native status information at *status to portable. |
| 30 | + */ |
| 31 | +static void status_ntop(int *status) |
| 32 | +{ |
| 33 | + int portable_status; |
| 34 | + |
| 35 | + ALOGV("%s(status:%p) {", __func__, |
| 36 | + status); |
| 37 | + |
| 38 | + ASSERT(status != NULL); |
| 39 | + |
| 40 | + /* |
| 41 | + * The interpretation of status is documented in the wait(2) manual page |
| 42 | + * and the implementation is in bionic/libc/include/sys/wait.h |
| 43 | + */ |
| 44 | + if (WIFSIGNALED(*status)) |
| 45 | + portable_status = (*status & ~0x7f) | signum_ntop(WTERMSIG(*status)); |
| 46 | + else if (WIFSTOPPED(*status)) |
| 47 | + portable_status = (*status & ~0xff00) | (signum_ntop(WSTOPSIG(*status)) << 8); |
| 48 | + else |
| 49 | + portable_status = *status; |
| 50 | + |
| 51 | + ALOGV("%s: (*status):0x%08x = portable_status:0x%08x", __func__, |
| 52 | + *status, portable_status); |
| 53 | + |
| 54 | + *status = portable_status; |
| 55 | + |
| 56 | + ALOGV("%s: return; }", __func__); |
| 57 | +} |
| 58 | + |
| 59 | + |
28 | 60 | pid_t WRAP(waitpid)(pid_t pid, int *status, int options)
|
29 | 61 | {
|
30 |
| - pid_t ret; |
31 |
| - |
32 |
| - ret = REAL(waitpid)(pid, status, options); |
33 |
| - if (status && ret > 0) { |
34 |
| - /* |
35 |
| - * Status layout is identical, so just the signal |
36 |
| - * number needs to be changed. |
37 |
| - */ |
38 |
| - if (WIFSIGNALED(*status)) |
39 |
| - *status = (*status & ~0x7f) | signum_ntop(WTERMSIG(*status)); |
40 |
| - else if (WIFSTOPPED(*status)) |
41 |
| - *status = (*status & ~0xff00) | (signum_ntop(WSTOPSIG(*status)) << 8); |
42 |
| - } |
43 |
| - |
44 |
| - return ret; |
| 62 | + pid_t rv; |
| 63 | + |
| 64 | + ALOGV("%s(pid:%d, status:%p, options:0x%x) {", __func__, |
| 65 | + pid, status, options); |
| 66 | + |
| 67 | + rv = REAL(waitpid)(pid, status, options); |
| 68 | + if (rv > 0 && status) |
| 69 | + status_ntop(status); |
| 70 | + |
| 71 | + ALOGV("%s: return rv:%d; }", __func__, rv); |
| 72 | + return rv; |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | +pid_t WRAP(wait)(int *status) |
| 77 | +{ |
| 78 | + pid_t rv; |
| 79 | + |
| 80 | + ALOGV("%s(status:%p) {", __func__, |
| 81 | + status); |
| 82 | + |
| 83 | + rv = REAL(wait)(status); |
| 84 | + if (rv > 0 && status) |
| 85 | + status_ntop(status); |
| 86 | + |
| 87 | + ALOGV("%s: return rv:%d; }", __func__, rv); |
| 88 | + return rv; |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | +pid_t WRAP(wait3)(int *status, int options, struct rusage *rusage) |
| 93 | +{ |
| 94 | + pid_t rv; |
| 95 | + |
| 96 | + ALOGV("%s(status:%p, options:0x%x, rusage:%p) {", __func__, |
| 97 | + status, options, rusage); |
| 98 | + |
| 99 | + rv = REAL(wait3)(status, options, rusage); |
| 100 | + if (rv > 0 && status) |
| 101 | + status_ntop(status); |
| 102 | + |
| 103 | + ALOGV("%s: return rv:%d; }", __func__, rv); |
| 104 | + return rv; |
| 105 | +} |
| 106 | + |
| 107 | + |
| 108 | +pid_t WRAP(wait4)(pid_t pid, int *status, int options, struct rusage *rusage) |
| 109 | +{ |
| 110 | + pid_t rv; |
| 111 | + |
| 112 | + ALOGV("%s(pid:%d, status:%p, options:0x%x, rusage:%p) {", __func__, |
| 113 | + pid, status, options, rusage); |
| 114 | + |
| 115 | + rv = REAL(wait4)(pid, status, options, rusage); |
| 116 | + if (rv > 0 && status) |
| 117 | + status_ntop(status); |
| 118 | + |
| 119 | + ALOGV("%s: return rv:%d; }", __func__, rv); |
| 120 | + return rv; |
45 | 121 | }
|
0 commit comments