|
|
cc [flag . . . ] file . . . -lgen [library] . . .#include <utmp.h>
struct utmp getutent (void);
struct utmp getutid (const struct utmp id);
struct utmp getutline (const struct utmp line);
struct utmp pututline (const struct utmp utmp);
void setutent (void);
void endutent (void);
int utmpname (const char file);
getutent 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.
getutid 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
RUN_LVL,
BOOT_TIME,
OLD_TIME,
or
NEW_TIME.
If the type specified in id is
INIT_PROCESS,
LOGIN_PROCESS,
USER_PROCESS,
or
DEAD_PROCESS,
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.
getutline searches forward from the current point in the utmp file until it finds an entry of the type LOGIN_PROCESS or USER_PROCESS that also has a ut_line string matching the line->ut_line string. If the end of file is reached without a match, it fails.
pututline writes out the supplied utmp structure into the 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 routines. 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. It returns a pointer to the utmp structure.
setutent resets the input stream to the beginning of the file. This reset should be done before each search for a new entry if it is desired that the entire file be examined.
endutent closes the currently open file.
utmpname allows the user to change the name of the file examined, from /var/adm/utmp to any other file. It is most often expected that this other file will be /var/adm/wtmp. If the file does not exist, this will not be apparent until the first attempt to reference the file is made. utmpname does not open the file. It just closes the old file if it is currently open and saves the new file name. If the file name given is longer than 79 characters, utmpname returns 0. Otherwise, it will return 1.
These routines use buffered standard I/O for input, but pututline uses an unbuffered non-standard write to avoid race conditions between processes trying to modify the utmp and wtmp files.