
#1487: unix package: test needed for getLoginName -------------------------------------+------------------------------------- Reporter: simonmar | Owner: thomie Type: bug | Status: new Priority: lowest | Milestone: 7.6.2 Component: libraries/unix | Version: 6.6.1 Resolution: | Keywords: Operating System: Linux | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by thomie): The attached patch fixes this issue. I tried going the pseudo-terminal route, but it doesn't work. System.Posix.User's `getLoginName` calls the C function `getlogin`. This function, on GNU/Linux at least, looks in the file /var/run/utmp for a login record with a tty name that matches that of the terminal connected to stdin (filedescriptor 0). It is possible to trick `getlogin` to check a pseudo terminal's name with something like: (master, slave) <- openPseudoTerminal dupTo master stdInput But, as far as I understand, pseudo-terminals are never registered in /var/run/utmp. Therefore `getlogin` will not find the user's login name and just return 'No such file or directory'. Maybe better than 'Inappropriate ioctl for device', but still an error. What does work, surprisingly, is adding this to `user001.hs`: dupTo stdOutput stdInput , but only if we wouldn't redirect stdout as well. The same for stderr. The solution is to simply not redirect stdin (i.e. don't do ./user001 < /dev/null). This implies skipping the ghci way. The commit that introduced the `no_stdin` test option alluded to this as well: fa52a8c9d8eae5e3fc4c0cf0e5672875e161e05c. One general concern is that there are no guarantees that `getlogin` will return anything other than NULL, so the test with this patch applied might fail on some systems. Another option therefore would be to turn the getLoginName test back off again, document why, and close this issue regardless. Review of -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/1487#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler