getppid.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * This file is part of Jehanne.
  3. *
  4. * Copyright (C) 2016 Giacomo Tesio <giacomo@tesio.it>
  5. *
  6. * Jehanne is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, version 2 of the License.
  9. *
  10. * Jehanne is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <u.h>
  19. #include <lib9.h>
  20. void
  21. main(void)
  22. {
  23. int ppid;
  24. Waitmsg *w;
  25. sys_rfork(RFNAMEG);
  26. if(sys_rfork(RFPROC) == 0){
  27. ppid = getmainpid(); // this comes from exec() syscall
  28. if(getppid() != ppid){
  29. print("FAIL: getppid() != getmainpid()\n");
  30. exits("FAIL");
  31. }
  32. sys_rfork(RFNOMNT);
  33. if(getppid() != ppid){
  34. print("FAIL: sys_rfork(RFNOMNT); getppid() != getmainpid()\n");
  35. exits("FAIL");
  36. }
  37. sys_rfork(RFNOMNT|RFCNAMEG);
  38. if(getppid() != ppid){
  39. print("FAIL: sys_rfork(RFNOMNT|RFCNAMEG)); getppid() != getmainpid()\n");
  40. exits("FAIL");
  41. }
  42. exits(nil);
  43. } else {
  44. w = wait();
  45. if(w->msg[0]){
  46. exits("FAIL");
  47. }
  48. print("PASS\n");
  49. exits("PASS");
  50. }
  51. }