[comp.unix.questions] /etc/utmp Question

brooks@corpane.UUCP (David E. Brooks Jr) (05/12/89)

I'm seeing a curious oddity that I think is related to something in
either the /etc/utmp or /etc/wtmp files.  I'm working with a replacement
login program that seems to work just fine on a serial line, but when
I login one of the consoles, or login over a ttyp line it leaves a
false entry that shows up in who.  Is there something additional I
need to do to either utmp/wtmp files (I'm using the getut library routines)
or am I missing something else?

Thanks,
-- 
David E. Brooks Jr                           UUCP :  ...!ddsw1!corpane!brooks
Corpane Industries Incorporated                      ...!ukma!corpane!brooks
10100 Bluegrass Parkway                      Phone:  +1 502 491 4433 x122
Louisville, KY  40299                        Quote:  printf("%c",34)

dag@per2.UUCP (Daniel A. Glasser) (05/20/89)

In article <628@corpane.UUCP>, brooks@corpane.UUCP (David E. Brooks Jr) writes:
> I'm seeing a curious oddity that I think is related to something in
> either the /etc/utmp or /etc/wtmp files.  I'm working with a replacement
> login program that seems to work just fine on a serial line, but when
> I login one of the consoles, or login over a ttyp line it leaves a
> false entry that shows up in who.  Is there something additional I
> need to do to either utmp/wtmp files (I'm using the getut library routines)
> or am I missing something else?

I ran into this same problem with my System-III box when I brought up my
own login.  The problem that I had was that my login program wrote entries
where it thought the console (tty1 on my machine) belonged based on the
minor device number whereas getty was using a different scheme.  It turned
out that the first entry was console, the second tty0, the third unused,
the fourth tty2, etc...  The function that I created to determine which
slot to use was as follows:

-----
#include <sys/types.h>
#include <sys/stat.h>

#ifndef CONSOLE
#define	CONSOLE	"/dev/console"
#endif

short utmpindex(term)
char *term;
{
	/* This code is ZEUS System III specific...  I don't know
	 * if it applies to any other system.
	 * For some reason, GETTY expects the console to be in position 0
	 * regardless of the TTY driver minor number.  This may be true of
	 * other Unix ports, but I have no way of knowing.
	 */

	struct stat buf;

	/* If the terminal turns out to be the console, use slot 0	*/
	if (!strcmp(term, CONSOLE))
		return 0;

	/* Stat(2) the terminal special file, we need it's minor number */
	if (stat(term, &buf))
		return -1;		/* error -- can't stat term */

	/* the utmp slot is the special file minor number + 1 */
	return (int)((buf.st_rdev & 0x00FF) + 1);
}

--------

Your system may use a different scheme, but it's easy to figure out.
Write a simple program that reads the utmp file sequentially and writes
each record out in order (formatted).  Use the original LOGIN program
and see where the utmp entries for the console are put.   I hope this
helps.

-- 
 _____________________________________________________________________________
    Daniel A. Glasser                           One of those things that goes
    uwvax!per2!dag                              "BUMP!!!(ouch)" in the night. 
 ---Persoft, Inc.---------465 Science Drive-------Madison, WI 53711-----------