getut(3) CLIX getut(3)
NAME
getut: getutent, getutid, getutline, pututline, setutent, endutent,
utmpname - Accesses utmp file entry
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <utmp.h>
struct utmp *getutent(
void );
struct utmp *getutid(
struct utmp *id );
struct utmp *getutline(
struct utmp *line );
void pututline(
struct utmp *utmp );
void setutent(
void );
void endutent(
void );
void utmpname(
char file );
PARAMETERS
id
line
utmp Specifies an entry in the utmp file.
file Specifies the name of a file other than the normal ``utmp'' file.
DESCRIPTION
The getutent(), getutid(), and getutline() functions each return a pointer
to a structure of the following type:
struct utmp {
char ut_user[8]; /* User login name */
char ut_id[4]; /* /etc/inittab id (usually line #) */
char ut_line[12]; /* device name (console, lnxx) */
2/94 - Intergraph Corporation 1
getut(3) CLIX getut(3)
short ut_pid; /* process id */
short ut_type; /* type of entry */
struct exit_status {
short e_termination; /* Process termination status */
short e_exit; /* Process exit status */
} ut_exit; /* The exit status of a process */
/* marked as DEAD_PROCESS. */
time_t ut_time; /* time entry was made */
}
The getutent() function reads in the next entry from a utmp-like file. If
the file is not already open, it opens it. If it reaches the end of the
file, it fails.
The getutid() function searches forward from the current point in the utmp
file until it finds an entry with a ut_type matching id->ut_type if the
type specified is or if the type specified in id is or then getutid() will
return a pointer to the first entry whose type is one of these four and
whose ut_id field matches id->ut_id. If the end-of-file is reached
without a match, it fails.
The getutline() function searches forward from the current point in the
utmp file until it finds an entry of the type LOGIN_PROCESS or
USER_PROCESS which also has a ut_line line->ut_line.
The pututline() function writes out the supplied utmp utmp file. It uses
getutid() to search forward for the proper place if it finds that it is
not already at the proper place. It is expected that normally the user of
pututline() will have searched for the proper entry using one of the getut
functions. If so, pututline() will not search. If pututline() does not
find a matching slot for the new entry, it will add a new entry to the end
of the file.
The setutent() function resets the input stream to the beginning of the
file. This should be done before each search for a new entry if it is
desired that the entire file be examined.
The endutent() function closes the currently open file.
The utmpname() function allows the user to change the name of the file
examined, from /etc/utmp to any other file. It is most often expected
that this other file will be /etc/wtmp. If the file does not exist, this
will not be apparent until the first attempt to reference the file is
made. The utmpname() function does not open the file. It just closes the
old file if it is currently open and saves the new filename.
FILES
/etc/utmp
/etc/wtmp
2 Intergraph Corporation - 2/94
getut(3) CLIX getut(3)
NOTES
The most current entry is saved in a static structure. Multiple accesses
require that it be copied before further accesses are made. Each call to
either getutid() or getutline() sees the function examine the static
structure before performing more I/O. If the contents of the static
structure match what it is searching for, it looks no further. For this
reason to use getutline() to search for multiple occurrences, it would be
necessary to zero out the static after each success, or getutline() would
just return the same pointer over and over again. There is one exception
to the rule about removing the structure before further reads are done.
The implicit read done by pututline() (if it finds that it is not already
at the correct place in the file) will not hurt the contents of the static
structure returned by the getutent(), getutid() or getutline() functions,
if the user has just modified those contents and passed the pointer back
to pututline().
These functions use buffered standard I/O for input, but pututline() uses
an unbuffered nonstandard write to avoid race conditions between processes
trying to modify the utmp and wtmp files.
RETURN VALUES
A NULL pointer is returned upon failure to read, whether for permissions
or having reached the end-of-file, or upon failure to write.
RELATED INFORMATION
Functions: ttyslot(3)
Files: utmp(4)
2/94 - Intergraph Corporation 3