1 /* 2 * Copyright 2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <portability.h> 18 #include <stdarg.h> 19 #include <stdlib.h> 20 #include <signal.h> 21 #include <signal_portable.h> 22 #include <stdio.h> 23 #include <sys/wait.h> 24 25 #define PORTABLE_TAG "waitpid_portable" 26 #include <log_portable.h> 27 28 pid_t WRAP(waitpid)(pid_t pid, int *status, int options) 29 { 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; 45 } 46