bindtest.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 <stdio.h>
  12. int
  13. cexecpipe(int *p0, int *p1)
  14. {
  15. /* pipe the hard way to get close on exec */
  16. if(bind("#|", "/mnt/temp", MREPL) < 0)
  17. return -1;
  18. //execl("/bin/ls", "ls", "-l", "/mnt/temp", 0);
  19. //wait();
  20. *p0 = open("/mnt/temp/data", ORDWR);
  21. *p1 = open("/mnt/temp/data1", ORDWR|OCEXEC);
  22. unmount(nil, "/mnt/temp");
  23. if(*p0<0 || *p1<0)
  24. return -1;
  25. return 0;
  26. }
  27. void main(int argc, char *argv[])
  28. {
  29. int f1, f2, ret;
  30. ret = cexecpipe(&f1, &f2);
  31. print("result %d f1 %d f2 %d\n", ret, f1, f2);
  32. if (ret < 0)
  33. {
  34. printf("FAIL\n");
  35. exits("FAIL");
  36. }
  37. else
  38. {
  39. printf("OK\n");
  40. exits("OK");
  41. }
  42. }