wait.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /* Wait for a child to die. When one does, put its status in *STAT_LOC
  13. * and return its process ID. For errors, return (pid_t) -1. */
  14. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  15. #include <errno.h>
  16. #include <sysdep-cancel.h>
  17. pid_t attribute_hidden
  18. __libc_wait (__WAIT_STATUS_DEFN stat_loc)
  19. {
  20. if (SINGLE_THREAD_P)
  21. return INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
  22. (struct rusage *) NULL);
  23. int oldtype = LIBC_CANCEL_ASYNC ();
  24. pid_t result = INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
  25. (struct rusage *) NULL);
  26. LIBC_CANCEL_RESET (oldtype);
  27. return result;
  28. }
  29. #else
  30. /* Wait for a child to die. When one does, put its status in *STAT_LOC
  31. * and return its process ID. For errors, return (pid_t) -1. */
  32. __pid_t __libc_wait (__WAIT_STATUS_DEFN stat_loc)
  33. {
  34. return wait4 (WAIT_ANY, stat_loc, 0, (struct rusage *) NULL);
  35. }
  36. #endif
  37. weak_alias(__libc_wait,wait)