os.getlogin() raises OSError (errno 25)

David Carson davidccarson at hotmail.com
Wed Jul 24 22:40:48 EDT 2002


Thanks, Donn.

All I did was replace os.getlogin() with pwd.getpwuid(os.geteuid()). 
The effective uid is what I really wanted anyway.

Cheers,
David

"Donn Cave" <donn at drizzle.com> wrote in message news:<1027489223.157336 at yasure>...
> Quoth davidccarson at hotmail.com (David Carson):
> | Could someone please explain why the following runs fine if I type the
> | input and end stdin with ctrl-D, but bombs when I pipe stdin to it.
>  ...
> |     loginName = os.getlogin()
> | OSError: [Errno 25] Inappropriate ioctl for device
>  ...
> | mandrake Linux 8.2
> 
> On NetBSD, it doesn't fail on a pipe, but man 2 getlogin mentions
> that it used to, in some earlier version of NetBSD, specifically if
> the process was not associated with a "login terminal."  Details
> vary from one platform to another (you don't want to know about the
> setpenv business on AIX), but characteristically it's a function of
> the terminal login session.  In theory, you'd get at the controlling
> terminal (if that's the same thing) by opening /dev/tty, and if you're
> really desperate you could try that out to see if you can work around
> some Linux brain damage:  open /dev/tty read/write, dup unit 0/1/2 to
> keep them around, dup2 the tty unit to 0/1/2, call getlogin, dup2 the
> saved units back and close the dups.  Of course it will be for naught
> if /dev/tty isn't a terminal - I'm just speculating that the brain
> damage is that GNU getlogin assumes /dev/tty is on 0 (or 1 or 2.)
> 
> Incidentally, on NetBSD I get "root" although I am not root.  That's
> probably because my sshd failed to call setlogin() - I don't know, but
> I've seen the same thing on other platforms for similar reasons.  One
> would not want to rely on this function for sensitive matters.  It's
> only good for a hint - if getuid() returns 0, you can try getlogin.
> 
> 	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list