setid.c 747 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * The process joins process group 0.
  3. */
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7. #include "test_helpers.h"
  8. int main(void) {
  9. int pg_status = setpgid(getpid(), 0);
  10. ERROR_IF(setpgid, pg_status, == -1);
  11. UNEXP_IF(setpgid, pg_status, != 0);
  12. printf("%d belongs to process group %d\n", getpid(), getpgrp());
  13. int reg_status = setregid(-1, -1);
  14. ERROR_IF(setregid, reg_status, == -1);
  15. UNEXP_IF(setregid, reg_status, != 0);
  16. printf("%d has egid %d and gid %d\n", getpid(), getegid(), getgid());
  17. int reu_status = setreuid(-1, -1);
  18. ERROR_IF(setreuid, reu_status, == -1);
  19. UNEXP_IF(setreuid, reu_status, != 0);
  20. printf("%d has euid %d and uid %d\n", getpid(), geteuid(), getuid());
  21. }