waitid.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2007 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <features.h>
  7. #if defined __USE_SVID || defined __USE_XOPEN
  8. #include <sys/syscall.h>
  9. #include <sys/wait.h>
  10. #include <cancel.h>
  11. #ifndef __NR_waitid
  12. # include <string.h>
  13. #endif
  14. static int __NC(waitid)(idtype_t idtype, id_t id, siginfo_t *infop, int options)
  15. {
  16. #ifdef __NR_waitid
  17. return INLINE_SYSCALL(waitid, 5, idtype, id, infop, options, NULL);
  18. #else
  19. switch (idtype) {
  20. case P_PID:
  21. if (id <= 0)
  22. goto invalid;
  23. break;
  24. case P_PGID:
  25. if (id < 0 || id == 1)
  26. goto invalid;
  27. id = -id;
  28. break;
  29. case P_ALL:
  30. id = -1;
  31. break;
  32. default:
  33. invalid:
  34. __set_errno(EINVAL);
  35. return -1;
  36. }
  37. memset(infop, 0, sizeof *infop);
  38. infop->si_pid = __NC(waitpid)(id, &infop->si_status, options
  39. # ifdef WEXITED
  40. &~ WEXITED
  41. # endif
  42. );
  43. if (infop->si_pid < 0)
  44. return infop->si_pid;
  45. return 0;
  46. #endif
  47. }
  48. CANCELLABLE_SYSCALL(int, waitid, (idtype_t idtype, id_t id, siginfo_t *infop, int options),
  49. (idtype, id, infop, options))
  50. #endif