waitid.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/types.h>
  10. # include <sys/wait.h>
  11. # include <sys/syscall.h>
  12. # ifdef __NR_waitid
  13. _syscall4(int, waitid, idtype_t, idtype, id_t, id, siginfo_t*, infop, int, options)
  14. # else
  15. # include <string.h>
  16. /* libc_hidden_proto(waitpid) */
  17. int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
  18. {
  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 = 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. }
  47. # endif
  48. #endif