waitid.c 1.1 KB

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