* [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
* [Caml-list] Re: Unix.getlogin () fails when stdin is redirected 2012-03-20 17:51 [Caml-list] Unix.getlogin () fails when stdin is redirected Ricardo Catalinas Jiménez @ 2012-03-20 18:07 ` Ricardo Catalinas Jiménez 2012-03-20 18:28 ` David House 2012-03-21 2:17 ` [Caml-list] " malc 1 sibling, 1 reply; 11+ messages in thread From: Ricardo Catalinas Jiménez @ 2012-03-20 18:07 UTC (permalink / raw) To: caml-list On Tue, Mar 20, 2012 at 06:51:13PM +0100, Ricardo Catalinas Jiménez wrote: > 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) = ? Someone knew the answer, man 3 getlogin reads: Note that glibc does not follow the POSIX specification and uses stdin instead of /dev/tty. A bug. (Other recent systems, like SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 all return the login name also when stdin is redirected.) Regards -- Ricardo (http://r.untroubled.be/) ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Re: Unix.getlogin () fails when stdin is redirected 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 0 siblings, 1 reply; 11+ messages in thread From: David House @ 2012-03-20 18:28 UTC (permalink / raw) To: Ricardo Catalinas Jiménez; +Cc: caml-list Note that Jane Street's core library [1] does not use getlogin(3) in its replacement Unix module, for exactly this reason: (* The standard getlogin function goes through utmp which is unreliable, see the BUGS section of getlogin(3) *) let getlogin_orig = Unix.getlogin let getlogin () = (Unix.getpwuid (getuid ())).Unix.pw_name [1]: https://bitbucket.org/yminsky/ocaml-core/wiki/Home I just tested your specific example, and it worked fine. On Tue 20 Mar 2012 06:07:59 PM GMT, Ricardo Catalinas Jiménez wrote: > On Tue, Mar 20, 2012 at 06:51:13PM +0100, Ricardo Catalinas Jiménez wrote: >> 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) = ? > > > Someone knew the answer, man 3 getlogin reads: > > Note that glibc does not follow the POSIX specification and uses > stdin instead of /dev/tty. A bug. (Other recent systems, like > SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 all return the login > name also when stdin is redirected.) > > > Regards ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Re: Unix.getlogin () fails when stdin is redirected 2012-03-20 18:28 ` David House @ 2012-03-20 18:48 ` Till Varoquaux 2012-03-20 19:41 ` Yaron Minsky 0 siblings, 1 reply; 11+ messages in thread From: Till Varoquaux @ 2012-03-20 18:48 UTC (permalink / raw) To: David House; +Cc: Ricardo Catalinas Jiménez, caml-list getpwuid(getuid()) is not a synonym for get_login (refer to the discussion in the POSIX standard[^1]). You should not shadow posix functions by functions with different semantics in the Unix modules; providing your own abstraction over the OS is a commendable goal but you should do so without silently bypassing core functions. Till [1]:http://pubs.opengroup.org/onlinepubs/007904975/functions/getlogin.html On Tue, Mar 20, 2012 at 2:28 PM, David House <dhouse@janestreet.com> wrote: > Note that Jane Street's core library [1] does not use getlogin(3) in its > replacement Unix module, for exactly this reason: > > (* The standard getlogin function goes through utmp which is unreliable, > see the BUGS section of getlogin(3) *) > let getlogin_orig = Unix.getlogin > let getlogin () = (Unix.getpwuid (getuid ())).Unix.pw_name > > [1]: https://bitbucket.org/yminsky/ocaml-core/wiki/Home > > I just tested your specific example, and it worked fine. > > > On Tue 20 Mar 2012 06:07:59 PM GMT, Ricardo Catalinas Jiménez wrote: >> >> On Tue, Mar 20, 2012 at 06:51:13PM +0100, Ricardo Catalinas Jiménez wrote: >>> >>> 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) = ? >> >> >> >> Someone knew the answer, man 3 getlogin reads: >> >> Note that glibc does not follow the POSIX specification and uses >> stdin instead of /dev/tty. A bug. (Other recent systems, like >> SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 all return the login >> name also when stdin is redirected.) >> >> >> Regards > > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Re: Unix.getlogin () fails when stdin is redirected 2012-03-20 18:48 ` Till Varoquaux @ 2012-03-20 19:41 ` Yaron Minsky 2012-03-20 20:12 ` Till Varoquaux 0 siblings, 1 reply; 11+ messages in thread From: Yaron Minsky @ 2012-03-20 19:41 UTC (permalink / raw) To: Till Varoquaux; +Cc: David House, Ricardo Catalinas Jiménez, caml-list [-- Attachment #1: Type: text/plain, Size: 3471 bytes --] Is there a concrete difference in behavior you're concerned about? y On Tue, Mar 20, 2012 at 2:48 PM, Till Varoquaux <till@pps.jussieu.fr> wrote: > getpwuid(getuid()) is not a synonym for get_login (refer to the > discussion in the POSIX standard[^1]). You should not shadow posix > functions by functions with different semantics in the Unix modules; > providing your own abstraction over the OS is a commendable goal but > you should do so without silently bypassing core functions. > > Till > [1]:http://pubs.opengroup.org/onlinepubs/007904975/functions/getlogin.html > > > On Tue, Mar 20, 2012 at 2:28 PM, David House <dhouse@janestreet.com> > wrote: > > Note that Jane Street's core library [1] does not use getlogin(3) in its > > replacement Unix module, for exactly this reason: > > > > (* The standard getlogin function goes through utmp which is unreliable, > > see the BUGS section of getlogin(3) *) > > let getlogin_orig = Unix.getlogin > > let getlogin () = (Unix.getpwuid (getuid ())).Unix.pw_name > > > > [1]: https://bitbucket.org/yminsky/ocaml-core/wiki/Home > > > > I just tested your specific example, and it worked fine. > > > > > > On Tue 20 Mar 2012 06:07:59 PM GMT, Ricardo Catalinas Jiménez wrote: > >> > >> On Tue, Mar 20, 2012 at 06:51:13PM +0100, Ricardo Catalinas Jiménez > wrote: > >>> > >>> 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) = ? > >> > >> > >> > >> Someone knew the answer, man 3 getlogin reads: > >> > >> Note that glibc does not follow the POSIX specification and uses > >> stdin instead of /dev/tty. A bug. (Other recent systems, like > >> SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 all return the login > >> name also when stdin is redirected.) > >> > >> > >> Regards > > > > > > > > > > -- > > Caml-list mailing list. Subscription management and archives: > > https://sympa-roc.inria.fr/wws/info/caml-list > > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > Bug reports: http://caml.inria.fr/bin/caml-bugs > > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > [-- Attachment #2: Type: text/html, Size: 5139 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Re: Unix.getlogin () fails when stdin is redirected 2012-03-20 19:41 ` Yaron Minsky @ 2012-03-20 20:12 ` Till Varoquaux 2012-03-20 22:45 ` oliver 0 siblings, 1 reply; 11+ messages in thread From: Till Varoquaux @ 2012-03-20 20:12 UTC (permalink / raw) To: yminsky; +Cc: David House, Ricardo Catalinas Jiménez, caml-list As far as I can tell getpwuid(geteuid()) is what the (deprecated) cuserid function does. The linux man page explains the difference between the two functions like this: _ These functions let your program identify positively the user who is running (cuserid()) or the user who logged in this session (getlogin()). (These can differ when set-user-ID programs are involved.) I expect there to be more points were the behaviours of those two functions diverge (e.g.: sudo, deamons etc...). In general I am very skeptic any time I see a one liner that is sold as a working alternative to a glibc function. The glibc has issues and pitfalls but they tend to be very well documented. "Better the devil you know"... Till On Tue, Mar 20, 2012 at 3:41 PM, Yaron Minsky <yminsky@gmail.com> wrote: > Is there a concrete difference in behavior you're concerned about? > > y > > > On Tue, Mar 20, 2012 at 2:48 PM, Till Varoquaux <till@pps.jussieu.fr> wrote: >> >> getpwuid(getuid()) is not a synonym for get_login (refer to the >> discussion in the POSIX standard[^1]). You should not shadow posix >> functions by functions with different semantics in the Unix modules; >> providing your own abstraction over the OS is a commendable goal but >> you should do so without silently bypassing core functions. >> >> Till >> [1]:http://pubs.opengroup.org/onlinepubs/007904975/functions/getlogin.html >> >> >> On Tue, Mar 20, 2012 at 2:28 PM, David House <dhouse@janestreet.com> >> wrote: >> > Note that Jane Street's core library [1] does not use getlogin(3) in its >> > replacement Unix module, for exactly this reason: >> > >> > (* The standard getlogin function goes through utmp which is unreliable, >> > see the BUGS section of getlogin(3) *) >> > let getlogin_orig = Unix.getlogin >> > let getlogin () = (Unix.getpwuid (getuid ())).Unix.pw_name >> > >> > [1]: https://bitbucket.org/yminsky/ocaml-core/wiki/Home >> > >> > I just tested your specific example, and it worked fine. >> > >> > >> > On Tue 20 Mar 2012 06:07:59 PM GMT, Ricardo Catalinas Jiménez wrote: >> >> >> >> On Tue, Mar 20, 2012 at 06:51:13PM +0100, Ricardo Catalinas Jiménez >> >> wrote: >> >>> >> >>> 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) = ? >> >> >> >> >> >> >> >> Someone knew the answer, man 3 getlogin reads: >> >> >> >> Note that glibc does not follow the POSIX specification and uses >> >> stdin instead of /dev/tty. A bug. (Other recent systems, like >> >> SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 all return the login >> >> name also when stdin is redirected.) >> >> >> >> >> >> Regards >> > >> > >> > >> > >> > -- >> > Caml-list mailing list. Subscription management and archives: >> > https://sympa-roc.inria.fr/wws/info/caml-list >> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> > Bug reports: http://caml.inria.fr/bin/caml-bugs >> > >> >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa-roc.inria.fr/wws/info/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Re: Unix.getlogin () fails when stdin is redirected 2012-03-20 20:12 ` Till Varoquaux @ 2012-03-20 22:45 ` oliver 2012-03-21 12:26 ` Török Edwin 0 siblings, 1 reply; 11+ messages in thread From: oliver @ 2012-03-20 22:45 UTC (permalink / raw) To: Till Varoquaux Cc: yminsky, David House, Ricardo Catalinas Jiménez, caml-list Are there so many bugs in glibc that fixing this one means waiting in a long, long queue... and bugfixes will need months or years? Are there any reasons this bug is not already fixed? And since when is it known? Ciao, Oliver On Tue, Mar 20, 2012 at 04:12:36PM -0400, Till Varoquaux wrote: > As far as I can tell getpwuid(geteuid()) is what the (deprecated) > cuserid function does. The linux man page explains the difference > between the two functions like this: > > _ These functions let your program identify positively the user who > is running (cuserid()) or the user who logged in this session > (getlogin()). (These can differ when set-user-ID programs are > involved.) > > I expect there to be more points were the behaviours of those two > functions diverge (e.g.: sudo, deamons etc...). > > In general I am very skeptic any time I see a one liner that is sold > as a working alternative to a glibc function. The glibc has issues and > pitfalls but they tend to be very well documented. "Better the devil > you know"... > > Till > > On Tue, Mar 20, 2012 at 3:41 PM, Yaron Minsky <yminsky@gmail.com> wrote: > > Is there a concrete difference in behavior you're concerned about? > > > > y > > > > > > On Tue, Mar 20, 2012 at 2:48 PM, Till Varoquaux <till@pps.jussieu.fr> wrote: > >> > >> getpwuid(getuid()) is not a synonym for get_login (refer to the > >> discussion in the POSIX standard[^1]). You should not shadow posix > >> functions by functions with different semantics in the Unix modules; > >> providing your own abstraction over the OS is a commendable goal but > >> you should do so without silently bypassing core functions. > >> > >> Till > >> [1]:http://pubs.opengroup.org/onlinepubs/007904975/functions/getlogin.html > >> > >> > >> On Tue, Mar 20, 2012 at 2:28 PM, David House <dhouse@janestreet.com> > >> wrote: > >> > Note that Jane Street's core library [1] does not use getlogin(3) in its > >> > replacement Unix module, for exactly this reason: > >> > > >> > (* The standard getlogin function goes through utmp which is unreliable, > >> > see the BUGS section of getlogin(3) *) > >> > let getlogin_orig = Unix.getlogin > >> > let getlogin () = (Unix.getpwuid (getuid ())).Unix.pw_name > >> > > >> > [1]: https://bitbucket.org/yminsky/ocaml-core/wiki/Home > >> > > >> > I just tested your specific example, and it worked fine. > >> > > >> > > >> > On Tue 20 Mar 2012 06:07:59 PM GMT, Ricardo Catalinas Jiménez wrote: > >> >> > >> >> On Tue, Mar 20, 2012 at 06:51:13PM +0100, Ricardo Catalinas Jiménez > >> >> wrote: > >> >>> > >> >>> 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) = ? > >> >> > >> >> > >> >> > >> >> Someone knew the answer, man 3 getlogin reads: > >> >> > >> >> Note that glibc does not follow the POSIX specification and uses > >> >> stdin instead of /dev/tty. A bug. (Other recent systems, like > >> >> SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 all return the login > >> >> name also when stdin is redirected.) > >> >> > >> >> > >> >> Regards > >> > > >> > > >> > > >> > > >> > -- > >> > Caml-list mailing list. Subscription management and archives: > >> > https://sympa-roc.inria.fr/wws/info/caml-list > >> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > >> > Bug reports: http://caml.inria.fr/bin/caml-bugs > >> > > >> > >> > >> -- > >> Caml-list mailing list. Subscription management and archives: > >> https://sympa-roc.inria.fr/wws/info/caml-list > >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > >> Bug reports: http://caml.inria.fr/bin/caml-bugs > >> > > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Re: Unix.getlogin () fails when stdin is redirected 2012-03-20 22:45 ` oliver @ 2012-03-21 12:26 ` Török Edwin 0 siblings, 0 replies; 11+ messages in thread From: Török Edwin @ 2012-03-21 12:26 UTC (permalink / raw) To: caml-list On 03/21/2012 12:45 AM, oliver wrote: > Are there so many bugs in glibc that fixing this one means waiting > in a long, long queue... and bugfixes will need months or years? > > Are there any reasons this bug is not already fixed? > And since when is it known? Using stdin might be on purpose, this is what a glibc comment says: /* Get name of tty connected to fd 0. Return NULL if not a tty or if fd 0 isn't open. Note that a lot of documentation says that getlogin() is based on the controlling terminal---what they really mean is "the terminal connected to standard input". The getlogin() implementation of DEC Unix, SunOS, Solaris, HP-UX all return NULL if fd 0 has been closed, so this is the compatible thing to do. Note that ttyname(open("/dev/tty")) on those systems returns /dev/tty, so that is not a possible solution for getlogin(). */ --Edwin ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Unix.getlogin () fails when stdin is redirected 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-21 2:17 ` malc 2012-03-21 11:29 ` Gerd Stolpmann 1 sibling, 1 reply; 11+ messages in thread From: malc @ 2012-03-21 2:17 UTC (permalink / raw) To: Ricardo Catalinas Jiménez; +Cc: caml-list On Tue, 20 Mar 2012, Ricardo Catalinas Jim?nez wrote: > 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: FWIW on my machine (linux) calling getlogin from any PTY always fails (be it screen or some sort of X terminal) [..snip..] -- mailto:av1474@comtv.ru ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Unix.getlogin () fails when stdin is redirected 2012-03-21 2:17 ` [Caml-list] " malc @ 2012-03-21 11:29 ` Gerd Stolpmann 2012-03-21 17:59 ` malc 0 siblings, 1 reply; 11+ messages in thread From: Gerd Stolpmann @ 2012-03-21 11:29 UTC (permalink / raw) To: malc; +Cc: "Ricardo Catalinas Jiménez", caml-list > On Tue, 20 Mar 2012, Ricardo Catalinas Jim?nez wrote: > >> 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: > > FWIW on my machine (linux) calling getlogin from any PTY always fails > (be it screen or some sort of X terminal) I guess /var/run/utmp is not world-readable - which is a perfectly reasonable configuration, and means that you disabled getlogin administratively. Does "last -f /var/run/utmp" give an output? Gerd > [..snip..] > > -- > mailto:av1474@comtv.ru > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > > -- Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de Creator of GODI and camlcity.org. Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de *** Searching for new projects! Need consulting for system *** programming in Ocaml? Gerd Stolpmann can help you. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Caml-list] Unix.getlogin () fails when stdin is redirected 2012-03-21 11:29 ` Gerd Stolpmann @ 2012-03-21 17:59 ` malc 0 siblings, 0 replies; 11+ messages in thread From: malc @ 2012-03-21 17:59 UTC (permalink / raw) To: Gerd Stolpmann; +Cc: "Ricardo Catalinas Jiménez", caml-list On Wed, 21 Mar 2012, Gerd Stolpmann wrote: > > > On Tue, 20 Mar 2012, Ricardo Catalinas Jim?nez wrote: > > > >> 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: > > > > FWIW on my machine (linux) calling getlogin from any PTY always fails > > (be it screen or some sort of X terminal) > > I guess /var/run/utmp is not world-readable - which is a perfectly > reasonable configuration, and means that you disabled getlogin > administratively. > > Does "last -f /var/run/utmp" give an output? Yep ~$ last -f /var/run/utmp malc tty1 Wed Mar 21 21:57 still logged in reboot system boot Wed Mar 21 21:57 (00:01) utmp begins Wed Mar 21 21:57:23 2012 ~$ ls -l /var/run/utmp -rw-r--r-- 1 root root 3840 2012-03-21 21:57 /var/run/utmp [..snip..] -- mailto:av1474@comtv.ru ^ 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