raz / test / run / ExecOpened.raz

16 lines · 540 B · raw · history · last change 22233765

1(* A file open gives is closed in the program exec runs, unless
2 keepOnExec says to keep it: of two opened files, sh sees the second. *)
3module ExecOpened;
4import Sys;
5
6proc main*: INT;
7var a, b: INT;
8begin
9 a := Sys.openRead("/dev/null");
10 b := Sys.create("/dev/null");
11 if (a # 3) or (b # 4) or (Sys.keepOnExec(b, true) # 0) then return 1; end;
12 return Sys.exec({path: "sh",
13 args: ["sh", "-c", "for n in 3 4; do if [ -e /proc/self/fd/$n ]; then echo open $n; else echo closed $n; fi; done"]});
14end;
15
16end ExecOpened.