wait.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (C) 2006 Steven J. Hill <sjhill@realitydiluted.com>
  3. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <stdlib.h>
  8. #include <syscall.h>
  9. #include <sys/types.h>
  10. #include <sys/wait.h>
  11. #include <sys/resource.h>
  12. extern __typeof(wait) __libc_wait;
  13. /* Wait for a child to die. When one does, put its status in *STAT_LOC
  14. * and return its process ID. For errors, return (pid_t) -1. */
  15. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  16. #include <errno.h>
  17. #include <sysdep-cancel.h>
  18. pid_t attribute_hidden
  19. __libc_wait (__WAIT_STATUS_DEFN stat_loc)
  20. {
  21. if (SINGLE_THREAD_P)
  22. return INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
  23. (struct rusage *) NULL);
  24. int oldtype = LIBC_CANCEL_ASYNC ();
  25. pid_t result = INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
  26. (struct rusage *) NULL);
  27. LIBC_CANCEL_RESET (oldtype);
  28. return result;
  29. }
  30. #else
  31. /* Wait for a child to die. When one does, put its status in *STAT_LOC
  32. * and return its process ID. For errors, return (pid_t) -1. */
  33. __pid_t __libc_wait (__WAIT_STATUS_DEFN stat_loc)
  34. {
  35. return wait4 (WAIT_ANY, stat_loc, 0, (struct rusage *) NULL);
  36. }
  37. #endif
  38. weak_alias(__libc_wait,wait)