thr_wait4.c revision 35509
113546Sjulian/* 235509Sjb * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> 313546Sjulian * All rights reserved. 413546Sjulian * 513546Sjulian * Redistribution and use in source and binary forms, with or without 613546Sjulian * modification, are permitted provided that the following conditions 713546Sjulian * are met: 813546Sjulian * 1. Redistributions of source code must retain the above copyright 913546Sjulian * notice, this list of conditions and the following disclaimer. 1013546Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1113546Sjulian * notice, this list of conditions and the following disclaimer in the 1213546Sjulian * documentation and/or other materials provided with the distribution. 1313546Sjulian * 3. All advertising materials mentioning features or use of this software 1413546Sjulian * must display the following acknowledgement: 1513546Sjulian * This product includes software developed by John Birrell. 1613546Sjulian * 4. Neither the name of the author nor the names of any co-contributors 1713546Sjulian * may be used to endorse or promote products derived from this software 1813546Sjulian * without specific prior written permission. 1913546Sjulian * 2013546Sjulian * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 2113546Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2213546Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2313546Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2413546Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2513546Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2613546Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2713546Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2813546Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2913546Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3013546Sjulian * SUCH DAMAGE. 3113546Sjulian * 3213546Sjulian */ 3313546Sjulian#include <errno.h> 3413546Sjulian#include <sys/wait.h> 3513546Sjulian#ifdef _THREAD_SAFE 3613546Sjulian#include <pthread.h> 3713546Sjulian#include "pthread_private.h" 3813546Sjulian 3913546Sjulianpid_t 4013546Sjulianwait4(pid_t pid, int *istat, int options, struct rusage * rusage) 4113546Sjulian{ 4213546Sjulian pid_t ret; 4313546Sjulian 4413546Sjulian /* Perform a non-blocking wait4 syscall: */ 4513546Sjulian while ((ret = _thread_sys_wait4(pid, istat, options | WNOHANG, rusage)) == 0 && (options & WNOHANG) == 0) { 4635509Sjb /* Reset the interrupted operation flag: */ 4735509Sjb _thread_run->interrupted = 0; 4835509Sjb 4913546Sjulian /* Schedule the next thread while this one waits: */ 5013546Sjulian _thread_kern_sched_state(PS_WAIT_WAIT, __FILE__, __LINE__); 5113546Sjulian 5213546Sjulian /* Check if this call was interrupted by a signal: */ 5335509Sjb if (_thread_run->interrupted) { 5435509Sjb errno = EINTR; 5513546Sjulian ret = -1; 5613546Sjulian break; 5713546Sjulian } 5813546Sjulian } 5913546Sjulian return (ret); 6013546Sjulian} 6113546Sjulian#endif 62