about summary refs log tree commit diff stats
path: root/src/local/container.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-23 02:04:42 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-23 02:04:42 +0200
commit860a1e77e40469753dbef080ee6fcc24f82dc847 (patch)
tree2f3abe60c1fe1fb408f7b20da80f2d575199bccf /src/local/container.nim
parentaa8f96765d1ddd85d0273d01cc9524514b6fe21f (diff)
downloadchawan-860a1e77e40469753dbef080ee6fcc24f82dc847.tar.gz
buffer: make readFromFd work with pipes
Diffstat (limited to 'src/local/container.nim')
-rw-r--r--src/local/container.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/local/container.nim b/src/local/container.nim
index d191c6b3..2f4d0044 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -983,7 +983,14 @@ proc setStream*(container: Container, stream: Stream) =
     container.iface = newBufferInterface(stream)
     if container.source.t == LOAD_PIPE:
       container.iface.passFd(container.source.fd).then(proc() =
-        discard close(container.source.fd))
+        discard close(container.source.fd)
+        if container.source.fd == 0:
+          # We have just closed stdin.
+          # Leaving the stdin fileno open to grab is a bad idea.
+          # (Yes, I've just got bitten by this: dup2(0, 0). Ouch.)
+          let devnull = open("/dev/null", O_RDONLY)
+          discard dup2(devnull, 0)
+      )
       stream.flush()
     container.load()
   else: