bindtest.c 988 B

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