United States-English |
|
|
HP-UX Reference > Ggetut(3C)TO BE OBSOLETEDHP-UX 11i Version 3: February 2007 |
|
NAMEgetut: 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 Interfacesint 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); DESCRIPTIONgetutent(), 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 */ };
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(). RETURN VALUEThese 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. WARNINGSgetutent_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. |
Printable version | ||
|