Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > G

getut(3C)

TO BE OBSOLETED
HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

getut: getutent(), getutid(), getutline(), pututline(), _pututline(), setutent(), endutent(), utmpname() — access utmp file entry

SYNOPSIS

#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 pututline(const struct utmp *utmp);

void setutent(void);

void endutent(void);

int utmpname(const char *file);

Obsolescent Interfaces

int getutent_r(struct utmp **utmp, struct utmp_data *ud); int getutid_r( struct utmp *id, struct utmp **utmp, struct utmp_data *ud); int getutline_r( struct utmp *line, struct utmp **utmp, struct utmp_data *ud); int pututline_r(const struct utmp *utmp, struct utmp_data *ud); void setutent_r(struct utmp_data *ud); void endutent_r(struct utmp_data *ud); int utmpname_r(const char *file);

DESCRIPTION

getutent(), getutid(), and getutline() 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) */ 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 */ time_t ut_time; /* time entry was made */ char ut_host[16]; /* host name, if remote;NOTSUPPORTED*/ unsigned long ut_addr; /* Internet addr of host, if remote */ };

getutent()

Reads in the next entry from a utmp-like file. If the file is not already open, getutent() opens it. If it reaches the end of the file, getutent() 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, getutid() 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, getutid() fails.

getutline()

Searches forward from the current point in the utmp 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, getutline() fails.

pututline()

Writes out the supplied utmp structure into the utmp file, translates the supplied utmp structure into a utmpx structure and writes it to a utmpx file. pututline() uses getutid() 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 getut() routines before calling pututline(). If the search as already been made, pututline() does not repeat it. If pututline() does not find a matching slot for the new entry, it adds a new entry to the end of the file.

_pututline()

Performs the same actions as pututline(), except that it returns a value useful for error checking.

setutent()

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.

endutent()

Closes the currently open file.

utmpname()

Allows the user to change the name of the file being examined from /etc/utmp and /etc/utmpx to any other files. In this case, the name provided to utmpname will be used for the utmp functions. An x will be appended to this name, and will be used by the getutx(3C) functions. The one exception to this are the putut() and pututx() functions as they access both files in an attempt to keep the utmp and utmpx files in sync. The other files are usually /var/adm/wtmp and /var/adm/wtmpx. If the files do not exist, the absence is not discovered until the first subsequent attempt to reference the file. utmpname() does not open the file; it merely closes the old file if it is currently open, and saves the new file name.

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 getutid() or getutline(), 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 you are using getutline() to search for multiple occurrences, it is necessary to zero out the static structure after each success; otherwise, getutline() 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 pututline() (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 getutent(), getutid(), or getutline() if the user has just modified those contents and passed the pointer back to pututline().

Obsolescent Interfaces

getutent_r(), getutid_r(), getutline_r(), pututline_r(), setutent_r(), endutent_r(), utmpname_r() access utmp file entry.

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 utmp).

_pututline() behaves the same as pututline(), except that it returns a pointer to a static location containing the most current utmp entry if the _pututline() call succeeds. The contents of this structure is identical to the contents of the supplied utmp structure if successful. If _pututline() fails upon writing to utmp, it returns a NULL pointer. If _putuline() is successful in writing to the utmp file and fails in writing to the utmpx file, then _pututline() will behave as if it succeeded. Please note that the utmp file and the utmpx file may not be in sync due to the above behavior. pututline() and _pututline() are only guaranteed to have written to the utmp file upon successful completion.

Reentrant Interfaces

Upon successful completion, getutent_r(), getutid_r(), getutline_r() and pututline_r() return 0. Otherwise, they all return -1 and set errno.

ERRORS

Reentrant Interfaces

EINVAL

The utmp or ud parameter is equal to NULL.

WARNINGS

getutent_r(), getutid_r(), getutline_r(), pututline_r(), setutent_r(), endutent_r(), and utmpname_r() are obsolescent interfaces supported only for compatibility with existing DCE applications. New multithreaded applications should use use the getutx(3C) functions that provide equivalent functionality.

Some vendors' versions of getutent() erase the utmp file if the file exists but is not an integral multiple of sizeof(struct utmp). Given the possibility of user error in providing a name to utmpname (such as giving improper arguments to who(1)), HP-UX does not do this, but instead returns an error indication.

For portability, getutx(3C) functions are preferred over these functions.

FILES

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

STANDARDS CONFORMANCE

endutent(): SVID2, SVID3, XPG2

getutent(): SVID2, SVID3, XPG2

getutid(): SVID2, SVID3, XPG2

getutline(): SVID2, SVID3, XPG2

pututline(): SVID2, SVID3, XPG2

setutent(): SVID2, SVID3, XPG2

utmpname(): SVID2, SVID3, XPG2

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.