Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Unix.getlogin () fails when stdin is redirected
@ 2012-03-20 17:51 Ricardo Catalinas Jiménez
  2012-03-20 18:07 ` [Caml-list] " Ricardo Catalinas Jiménez
  2012-03-21  2:17 ` [Caml-list] " malc
  0 siblings, 2 replies; 11+ messages in thread
From: Ricardo Catalinas Jiménez @ 2012-03-20 17:51 UTC (permalink / raw)
  To: caml-list

I found out the next issue in this simple code:

let () =
    print_endline "Hello";
    print_endline (Unix.getlogin ())

Running in the normal case, with `./a.out' gives:

Hello
ricardo

But running like `./a.out </dev/null' makes Unix.getlogin fail:

Hello
Fatal error: exception Unix.Unix_error(20, "getlogin", "")

A simple strace reveals the problem:

   open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
   fstat(3, {st_mode=S_IFREG|0644, st_size=509, ...}) = 0
   mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb125554000
   read(3, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 509
   read(3, "", 4096)                       = 0
   close(3)                                = 0
   munmap(0x7fb125554000, 4096)            = 0
-> ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff12682c98) = -1 ENOTTY (Inappropriate ioctl for device)
   write(2, "Fatal error: exception Unix.Unix"..., 59) = 59
   exit_group(2)                           = ?

Any idea how to fix this?


Best regards
-- 
Ricardo (http://r.untroubled.be/)

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-03-21 18:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-20 17:51 [Caml-list] Unix.getlogin () fails when stdin is redirected Ricardo Catalinas Jiménez
2012-03-20 18:07 ` [Caml-list] " Ricardo Catalinas Jiménez
2012-03-20 18:28   ` David House
2012-03-20 18:48     ` Till Varoquaux
2012-03-20 19:41       ` Yaron Minsky
2012-03-20 20:12         ` Till Varoquaux
2012-03-20 22:45           ` oliver
2012-03-21 12:26             ` Török Edwin
2012-03-21  2:17 ` [Caml-list] " malc
2012-03-21 11:29   ` Gerd Stolpmann
2012-03-21 17:59     ` malc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox