getutx(3C) getutx(3C)
NAME
getutxent(), getutxid(), getutxline(), pututxline(), setutxent(),
endutxent() - access utmpx file entry
SYNOPSIS
#include <<<<utmpx.h>>>>
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *id);
struct utmpx *getutxline(const struct utmpx *line);
struct utmpx *pututxline(const struct utmpx *utmpx);
void setutxent(void);
void endutxent(void);
DESCRIPTION
getutxent(), getutxid(), and getutxline() each return a pointer to a
structure of the following type:
struct utmpx {
char ut_user[24]; /* User login name */
char ut_id[4]; /* /etc/inittab id (usually line #) */
char ut_line[12]; /* device name (console, lnxx) */
pid_t 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. */
unsigned short ut_reserved1; /* Reserved for future use */
struct timeval {
time_t tv_sec; /* seconds */
long tv_usec; /* and microseconds */
} ut_tv; /* time entry was made */
char ut_host[64]; /* host name, if remote; NOT SUPPORTED */
unsigned long ut_addr; /* Internet addr of host, if remote */
char ut_reserved2[12] ; /* Reserved for future use */
};
getutxent() Reads in the next entry from a utmpx-like file.
If the file is not already open, getutxent() opens
it. If it reaches the end of the file,
getutxent() fails.
getutxid() Searches forward from the current point in the
utmpx file until it finds an entry with a ut_type
Hewlett-Packard Company - 1 - HP-UX Release 11i: November 2000
getutx(3C) getutx(3C)
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,
getutxid() returns a pointer to the first entry
whose type is one of these four, and whose ut_id
field matches id->ut_id. If end-of-file is
reached without a match, getutxid() fails.
getutxline() Searches forward from the current point in the
utmpx file until it finds an entry of type
LOGIN_PROCESS or USER_PROCESS that also has a
ut_line string matching the line->ut_line string.
If end-of-file is reached without a match,
getutxline() fails.
pututxline() Writes out the supplied utmpx structure into the
utmpx file, translates the supplied utmpx
structure into a utmp structure and writes it to a
utmp file. pututxline() uses getutxid() to search
forward for the proper location if it is not
already there. It is normally expected that the
application program has already searched for the
proper entry by using one of the getutx() routines
before calling pututxline(). If the search has
already been made, pututxline() does not repeat
it. If pututxline() does not find a matching slot
for the new entry, it adds a new entry to the end
of the file.
setutxent() 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.
endutxent() Closes the currently open file.
The most current entry is saved in a static structure. Multiple
accesses require that the structure be copied before further accesses
are made. During each call to either getutxid() or getutxline(), the
static structure is examined before performing more I/O. If the
contents of the static structure match what the routine is searching
for, no additional searching is done. Therefore, if using
getutxline() to search for multiple occurrences, it is necessary to
zero out the static structure after each success; otherwise
getutxline() simply returns the same pointer over and over again.
There is one exception to the rule about removing the structure before
a new read: The implicit read done by pututxline() (if it finds that
it is not already at the correct place in the file) does not alter the
contents of the static structure returned by getutxent(), getutxid(),
or getutxline() if the user has just modified those contents and
Hewlett-Packard Company - 2 - HP-UX Release 11i: November 2000
getutx(3C) getutx(3C)
passed the pointer back to pututxline().
RETURN VALUE
These functions return a NULL pointer upon failure to read (whether
for permissions or having reached end-of-file), or upon failure to
write. They also return a NULL pointer if the size of the file is not
an integral multiple of sizeof(struct utmpx).
If pututxline() is successful, it returns a pointer to a static
location containing the most current utmpx entry. The contents of
this structure are identical to the contents of the supplied utmpx
structure if successful. If pututline() fails upon writing to utmpx,
it returns a NULL pointer. If putuline() is successful in writing to
the utmpx file but fails in writing to the utmp file, then pututline()
will behave as if it succeeded. Note that the utmpx file and the utmp
file may not be in sync due to the above behavior. pututxline() is
only guaranteed to have written to the utmpx file upon successful
completion.
APPLICATION USAGE
getutxent(), getutxid(), getutxline(), pututxline(), setutxent() and
endutxent() are thread-safe. These interfaces are not async-cancel-
safe. A cancellation point may occur when a thread is executing these
interfaces.
FILES
/etc/utmp
/etc/utmpx
/var/adm/wtmp
SEE ALSO
ttyslot(3C), utmp(4), getut(3C), getutent(3C).
STANDARDS CONFORMANCE
endutxent(): XPG4.2
getutxent(): XPG4.2
getutxid(): XPG4.2
getutxline(): XPG4.2
pututxline(): XPG4.2
setutxent(): XPG4.2
Hewlett-Packard Company - 3 - HP-UX Release 11i: November 2000
|