Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,334
    • Issues 4,334
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 370
    • Merge Requests 370
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #431

Closed
Open
Opened Aug 01, 2005 by nobody@trac-nobody

runInteractiveProcess and closed stdin.

Hello,

The System.Process.runInteractiveProcess function
doesn't seem to provide the child process with a stdin
handle when the parent's stdin is closed. Below is a
small example:

import System.Process
import Control.Concurrent
import System.IO

main = do
  hClose stdin -- everything works as expected if the
handle isn't closed.
  putStrLn "Running cat ..."
  (inp, out, err, pid) <- runInteractiveProcess "cat"
[] Nothing Nothing
  forkIO (hPutStrLn inp "foo" >> hClose inp)
  forkIO (putStrLn =<< hGetContents out)
  forkIO (putStrLn =<< hGetContents err)
  -- Don't want to deal with waitForProcess and
-threaded right now.
  threadDelay 1000000
  return ()

Running this example produces the error

% ghc Run.hs -o run
% ./run
Running cat ...

cat: -: Bad file descriptor
cat: closing standard input: Bad file descriptor


I think the bug is in
fptools/libraries/base/cbits/runProcess.c:
//...
    pipe(fdStdInput);
//...
        dup2 (fdStdInput[0], STDIN_FILENO);
/...	
	close(fdStdInput[0]);
//...

pipe(...) will assign the lowest available file
descriptors, i.e. 0 if stdin is closed. The dup2 won't
do anything, since src and dest fds are identical, so
close(...) will close the child's stdin immediately.


% uname -a
Linux mthomas 2.6.12 #2 Thu Jul 21 07:51:44 EDT 2005
i686 GNU/Linux
% ghc --version
The Glorious Glasgow Haskell Compilation System,
version 6.5.20050728

Thanks,

-- Thomas Jäger
Edited Mar 09, 2019 by Ian Lynagh <igloo@earth.li>
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#431