Works like waitpid(), but if we already harvested the child pid in our * remember_children(), we succeed instead of returning an error. */
| 146 | /* Works like waitpid(), but if we already harvested the child pid in our |
| 147 | * remember_children(), we succeed instead of returning an error. */ |
| 148 | pid_t wait_process(pid_t pid, int *status_ptr, int flags) |
| 149 | { |
| 150 | pid_t waited_pid; |
| 151 | |
| 152 | do { |
| 153 | waited_pid = waitpid(pid, status_ptr, flags); |
| 154 | } while (waited_pid == -1 && errno == EINTR); |
| 155 | |
| 156 | if (waited_pid == -1 && errno == ECHILD) { |
| 157 | /* Status of requested child no longer available: check to |
| 158 | * see if it was processed by remember_children(). */ |
| 159 | int cnt; |
| 160 | for (cnt = 0; cnt < MAXCHILDPROCS; cnt++) { |
| 161 | if (pid == pid_stat_table[cnt].pid) { |
| 162 | *status_ptr = pid_stat_table[cnt].status; |
| 163 | pid_stat_table[cnt].pid = 0; |
| 164 | return pid; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return waited_pid; |
| 170 | } |
| 171 | |
| 172 | int shell_exec(const char *cmd) |
| 173 | { |
no test coverage detected