rfork.c 904 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <fcall.h>
  12. #include <thread.h>
  13. #include <9p.h>
  14. static void
  15. rforker(void (*fn)(void*), void *arg, int flag)
  16. {
  17. switch(rfork(RFPROC|RFMEM|RFNOWAIT|flag)){
  18. case -1:
  19. sysfatal("rfork: %r");
  20. default:
  21. return;
  22. case 0:
  23. fn(arg);
  24. _exits(0);
  25. }
  26. }
  27. void
  28. listensrv(Srv *s, char *addr)
  29. {
  30. _forker = rforker;
  31. _listensrv(s, addr);
  32. }
  33. void
  34. postmountsrv(Srv *s, char *name, char *mtpt, int flag)
  35. {
  36. _forker = rforker;
  37. _postmountsrv(s, name, mtpt, flag);
  38. }