1 /* wait.cc: Posix wait routines.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2009, 2011 Red Hat, Inc.
6 This file is part of Cygwin.
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
18 /* This is called _wait and not wait because the real wait is defined
19 in libc/syscalls/syswait.c. It calls us. */
24 return wait4 (-1, status, 0, NULL);
28 waitpid (pid_t intpid, int *status, int options)
30 return wait4 (intpid, status, options, NULL);
34 wait3 (int *status, int options, struct rusage *r)
36 return wait4 (-1, status, options, r);
39 /* Wait for any child to complete.
40 * Note: this is not thread safe. Use of wait in multiple threads will
45 wait4 (int intpid, int *status, int options, struct rusage *r)
49 waitq *w = &_my_tls.wq;
51 pthread_testcancel ();
55 sig_dispatch_pending ();
56 if (options & ~(WNOHANG | WUNTRACED | WCONTINUED))
64 memset (r, 0, sizeof (*r));
69 sigproc_printf ("calling proc_subproc, pid %d, options %d",
71 if (!proc_subproc (PROC_WAIT, (DWORD) w))
74 paranoid_printf ("proc_subproc returned 0");
79 if ((waitfor = w->ev) == NULL)
82 res = cancelable_wait (waitfor);
84 sigproc_printf ("%d = WaitForSingleObject (...)", res);
89 /* found no children */
97 if (_my_tls.call_signal_handler ())
99 set_sig_errno (EINTR);
102 else if (res != WAIT_OBJECT_0)
107 else if ((res = w->pid) != 0 && status)
112 sigproc_printf ("intpid %d, status %p, w->status %d, options %d, res %d",
113 intpid, status, w->status, options, res);
116 sigproc_printf ("*** errno %d", get_errno ());