Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 6.9 System Identification 187


struct utmp {
char ut_line[8]; /* tty line: "ttyh0", "ttyd0", "ttyp0", ... */
char ut_name[8]; /* login name */
long ut_time; /* seconds since Epoch */
};

On login, one of these structures was filled in and written to theutmpfile by thelogin
program, and the same structurewas appended to thewtmpfile. On logout, the entry
in theutmpfile was erased—filled with null bytes—bytheinitprocess, and a new
entry was appended to thewtmpfile. This logout entry in the wtmpfile had the
ut_namefield zeroed out. Special entries wereappended to thewtmpfile to indicate
when the system was rebooted and right beforeand after the system’s time and date
was changed. Thewho( 1 )program read theutmpfile and printed its contents in a
readable form. Later versions of the UNIX System provided thelast( 1 )command,
which read through thewtmpfile and printed selected entries.
Most versions of the UNIX System still provide theutmpandwtmpfiles, but as
expected, the amount of information in these files has grown. The 20-byte structurethat
was written by Version 7 grew to 36 bytes with SVR2, and the extendedutmpstructure
with SVR4 takes morethan 350 bytes!

The detailed format of these records in Solaris is given in theutmpx(4) manual page.With
Solaris 10, both files are in the/var/admdirectory.Solaris provides numerous functions
described ingetutxent(3) to read and write these two files.

On FreeBSD 8.0 and Linux 3.2.0, theutmp(5) manual page gives the format of their versions of
these login records. The pathnames of these two files are /var/run/utmp and
/var/log/wtmp.OnMac OS X 10.6.8, theutmpandwtmpfiles do not exist. As of Mac OS X
10.5, the information found in thewtmpfile can be obtained from the system logging facility,
and theutmpxfile contains information about the active login sessions.

6.9 System Identification


POSIX.1 defines theunamefunction to return information on the current host and
operating system.

#include <sys/utsname.h>

int uname(struct utsname *name);

Returns: non-negative value if OK,−1 on error

We pass the address of autsnamestructure to this function, and the function then fills
it in. POSIX.1 defines only the minimum fields in the structure, which areall character
arrays, and it’s up to each implementation to set the size of each array.Some
implementations provide additional fields in the structure.
Free download pdf