| 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. *) |
| 3 | module ExecOpened; |
| 4 | import Sys; |
| 5 | |
| 6 | proc main*: INT; |
| 7 | var a, b: INT; |
| 8 | begin |
| 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"]}); |
| 14 | end; |
| 15 | |
| 16 | end ExecOpened. |