[comp.unix.wizards] getlogin

lenny@quincy.UUCP (Lenny Tropiano) (12/09/87)

On my UNIX PC I have noticed a problem occasionally with the
getlogin(3C) system call.  At certain times I have noticed
getlogin returning "LOGIN" or "rc" instead of the user's name
who is logged in.

I know what "LOGIN" and "rc" are, but why are they showing up
for a valid logged-in user?  This is quite strange...

--- piece of code ---

	char	*getlogin();

	printf("User is: %s\n", getlogin());

--- end piece of code ---

Any suggestions?  I have recreated the /etc/utmp, /etc/wtmp and
this hasn't cleared up the problem.  Sometimes it goes away
and other times it comes back.

						Thanks,
						Lenny
-- 
Lenny Tropiano                  UUCP:      ...uunet!godfre!quincy!lenny  -or-
American LP Systems, Inc.        ...cmcl2!phri!bc-cis!icus!quincy!lenny  -or-
1777-18 Veterans Memorial Hwy.   	          ...mtune!quincy!lenny  -or
Islandia, New York 11722     +1 516-582-5525 ...ihnp4!icus!quincy!lenny

ignatz@chinet.UUCP (Dave Ihnat) (12/12/87)

Yep; I've seen this one, when I was porting 'mdm'.  I'll bet you're
running more than one shell login window.  It seems that getlogin() isn't
quite swift enough to differentiate between the physical device--probably
'console'--and the virtual windows 'w1', 'w2', etc. on that device; so
it'll return whatever it finds first in /etc/utmp.  I haven't spent
the time yet to yank the object out of the library, rewrite it, stuff
it back in the library, etc.  Not to mention having to muddle around
in the shared library...
-- 
			Dave Ihnat
			ihnp4!homebru!ignatz || ihnp4!chinet!ignatz
			(w) (312) 882-4673

jlunny@NSWC-G.arpa (12/15/87)

i've noticed this problem within the AT&T environment on a Pyramid.
The problem would surface in some of my background processes.  it is a
bug in getlogin(), but it was decided it was not important enough to
be fixed here at this site (like alot of Pyramid's little quirks, but who's
here to complain).

jlunny
disclaimer:  "I know nothin', I say nothin'."

allbery@ncoast.UUCP (Brandon Allbery) (12/20/87)

As quoted from <10848@brl-adm.ARPA> by jlunny@NSWC-G.arpa:
+---------------
| i've noticed this problem within the AT&T environment on a Pyramid.
| The problem would surface in some of my background processes.  it is a
| bug in getlogin(), but it was decided it was not important enough to
| be fixed here at this site (like alot of Pyramid's little quirks, but who's
| here to complain).
+---------------

The problem on the Pyramid is probably a bad translation of a BSD /etc/utmp
(I assume you boot using BSD files rather than AT&T files; I'm told one could
use either) to AT&T format.

On the 3B1 (the original problem), the problem is caused by the fact that the
only way to create a new window is to open /dev/window, which metamorphoses
into a /dev/w[0-9] automagically.  Needless to say, this is cleaner for a
program than the way used to get e.g. ptys, but requires rooting through /dev
if the program wants the name of the *real* window device it's using.  (On
3.51 it seems to work correctly; my "w", at least, says I'm logged in on "w1",
and it *doesn't* do any mucking around with window devices.)

A quick fix:  "ln" /dev/window to "/dev/wdev01" and "/dev/wdev02", then set
up a getty on each.  However, this can backfire if someone writes to a user
from the console -- if "write" doesn't track windows the respondent could
end up writing to an otherwise-empty window....
-- 
Brandon S. Allbery		      necntc!ncoast!allbery@harvard.harvard.edu
 {hoptoad,harvard!necntc,cbosgd,sun!mandrill!hal,uunet!hnsurg3}!ncoast!allbery
			Moderator of comp.sources.misc