DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

getutx(S-osr5)


getutx -- access utmpx file entry

Syntax

cc ...-lc

#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);

int utmpxname (const char *file);

void updwtmpx (const char *wfilex, struct utmpx *utmpx);

cc ...-lc

#include <utmpx.h>

void getutmp (const struct utmpx *utmpx, struct utmp *utmp);

void getutmpx (const struct utmp *utmp, struct utmpx *utmpx);

void updwtmp (const char *wfile, struct utmp *utmp);

Description

getutxent(S-osr5), getutxid(S-osr5), getutxline(S-osr5) and pututxline(S-osr5) each return a pointer to a utmpx structure. (See utmpx(F).)

getutxent( ) reads in the next entry from a utmpx-like file. If the file is not already open, it opens it. If it reaches the end of the file, it fails.

The action of getutxid( ) depends on the type of entry. If the type specified is RUN_LVL, BOOT_TIME, OLD_TIME, or NEW_TIME, getutxid( ) searches forward from the current point in the utmpx file until it finds an entry with a ut_type matching id->ut_type. But if the type specified in id is one of INIT_PROCESS, LOGIN_PROCESS, USER_PROCESS, or DEAD_PROCESS, it returns a pointer to the first entry whose type is one of these four and whose ut_id field matches id->ut_id. If getutxid( ) reaches the end of file without a match, it fails.

getutxline( ) searches forward from the current point in the utmpx file until it finds an entry of the type LOGIN_PROCESS or USER_PROCESS which also has a ut_line string matching the line->ut_line string. If it reaches the end of file without a match, it fails.

pututxline( ) writes out the supplied utmpx structure into the utmpx file. If it is not already at the proper place, it uses getutxid( ) to search forward for the proper place. Normally, the user of pututxline( ) searches for the proper entry using one of the getutx(S-osr5) routines. If so, pututxline( ) does not search. If pututxline( ) does not find a matching slot for the new entry, it adds a new entry to the end of the file. It returns a pointer to the utmpx structure.

setutxent(S-osr5) resets the input stream to the beginning of the file. Do this before each search for a new entry if you want to examine the entire file.

endutxent(S-osr5) closes the currently open file.

utmpxname(S-osr5) allows the user to change the name of the file examined, from /var/adm/utmpx to any other file. This other file is usually /var/adm/wtmpx. If the file does not exist, that is not apparent until the first attempt to reference the file is made. utmpxname( ) does not open the file. It just closes the old file if it is currently open and saves the new file name. The new file name must end with ``x'' to allow the name of the corresponding utmp file to be easily obtainable (otherwise an error code of 0 is returned).

getutmp(S-osr5) copies the information stored in the fields of the utmpx structure to the corresponding fields of the utmp structure. If the information in any field of utmpx does not fit in the corresponding utmp field, the data is truncated.

getutmpx(S-osr5) copies the information stored in the fields of the utmp structure to the corresponding fields of the utmpx structure.

updwtmp(S-osr5) checks the existence of wfile and its parallel file wfilex, whose name is obtained by appending an ``x'' to wfile. If only one of them exists, the other is created and initialized to reflect the state of the existing file. utmp is written to wfile and the corresponding utmpx structure is written to the parallel file. If neither file exists nothing happens.

updwtmpx(S-osr5) checks the existence of wfilex and its parallel file wfile, whose name is obtained by removing the final ``x'' from wfilex. If only one of them exists, the other is created and initialized to reflect the state of the existing file. utmpx is written to wfilex, and the corresponding utmp structure is written to the parallel file. If neither file exists nothing happens.

Repeated access

The most current entry is saved in a static structure. For multiple accesses, copy the current entry before making further accesses. On each call to either getutxid( ) or getutxline( ), the routine examines the static structure before doing more I/O. If the contents of the static structure match what it is searching for, it looks no further. For that reason, if you use getutxline( ) to search for multiple occurrences, you must zero out the static structure after each success, or getutxline( ) just returns the same structure over and over again.

There is one exception to the rule about emptying the structure before further reads are done. The implicit read done by pututxline( ) (if it finds that it is not already at the correct place in the file) does not hurt the contents of the static structure returned by getutxent( ), getutxid( ), or getutxline( ), if you have just modified those contents and passed the pointer back to pututxline( ).

These routines use buffered standard I/O for input, but pututxline( ) uses an unbuffered write to avoid race conditions between processes trying to modify the utmpx and wtmpx files.

Return values

A null pointer is returned on failure to read, whether for permissions or having reached the end of file, or on failure to write.

Diagnostics

This function does not set errno.

Files


/etc/utmp
/etc/utmpx
/etc/wtmp
/etc/wtmpx
/var/adm/utmp
/var/adm/utmpx
/var/adm/wtmp
/var/adm/wtmpx

See also

getut(S-osr5), ttyslot(S-osr5), utmp(F), utmpx(F)

Standards conformance

utmpxname(S-osr5), getutmp(S-osr5), getutmpx(S-osr5), updwtmp(S-osr5), and updwtmpx(S-osr5) are not part of any currently supported standard; they were developed by UNIX System Laboratories, Inc. and are maintained by The SCO Group.

getutxent(S-osr5), getutxid(S-osr5), getutxline(S-osr5), pututxline(S-osr5), setutxent(S-osr5), and endutxent(S-osr5) are conformant with:

X/Open CAE Specification, System Interfaces and Headers, Issue 4, Version 2.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005