1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
.\" Copyright 1995 Mark D. Roth (roth@uiuc.edu)
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
.\" USA.
.\"
.\" References consulted:
.\" Linux libc source code
.\" Solaris manpages
.\"
.\" Modified Thu Jul 25 14:43:46 MET DST 1996 by Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
.\"
.TH GETUTENT 3 "July 25, 1996" "" "Library functions"
.SH NAME
getutent, getutid, getutline, pututline, setutent, endutent, utmpname \- access utmp file entries
.SH SYNOPSIS
.B #include <utmp.h>
.sp
.B struct utmp *getutent(void);
.br
.BI "struct utmp *getutid(struct utmp *" ut ");"
.br
.BI "struct utmp *getutline(struct utmp *" ut ");"
.sp
.BI "void pututline(struct utmp *" ut ");"
.sp
.B void setutent(void);
.br
.B void endutent(void);
.sp
.BI "void utmpname(const char *" file ");"
.SH DESCRIPTION
\fButmpname\fP() sets the name of the utmp-format file for the other utmp
functions to access. If \fButmpname\fP() is not used to set the filename
before the other functions are used, they assume \fB_PATH_UTMP\fP, as
defined in \fI<paths.h>\fP.
.PP
\fBsetutent\fP() rewinds the file pointer to the beginning of the utmp file.
It is generally a Good Idea to call it before any of the other
functions.
.PP
\fBendutent\fP() closes the utmp file. It should be called when the user
code is done accessing the file with the other functions.
.PP
\fBgetutent\fP() reads a line from the current file position in the utmp
file. It returns a pointer to a structure containing the fields of
the line.
.PP
\fBgetutid\fP() searches forward from the current file position in the utmp
file based upon \fIut\fP. If \fIut\fP\fB->ut_type\fP is \fBRUN_LVL\fP,
\fBBOOT_TIME\fP, \fBNEW_TIME\fP, or \fBOLD_TIME\fP, \fBgetutid\fP() will
find the first entry whose \fBut_type\fP field matches \fIut\fP\fB->ut_type\fP.
If \fIut\fP\fB->ut_type\fP is one of \fBINIT_PROCESS\fP, \fBLOGIN_PROCESS\fP,
\fBUSER_PROCESS\fP, or \fBDEAD_PROCESS\fP, \fBgetutid\fP() will find the
first entry whose \fBut_id\fP field matches \fIut\fP\fB->ut_id\fP.
.PP
\fBgetutline\fP() searches forward from the current file position in the
utmp file. It scans entries whose ut_type is \fBUSER_PROCESS\fP
or \fBLOGIN_PROCESS\fP and returns the first one whose \fBut_line\fP field
matches \fIut\fP\fB->ut_line\fP.
.PP
\fBpututline\fP() writes the utmp structure \fIut\fP into the utmp file. It
uses \fBgetutid\fP() to search for the proper place in the file to insert
the new entry. If it cannot find an appropriate slot for \fIut\fP,
\fBpututline\fP() will append the new entry to the end of the file.
.SH "RETURN VALUE"
\fBgetutent\fP(), \fBgetutid\fP(), and \fBgetutline\fP() return a pointer to a \fBstatic struct
utmp\fP.
.SH "ERRORS"
On error, \fB(struct utmp*)0\fP will be returned.
.SH EXAMPLE
The following example adds and removes a utmp record, assuming it is run
from within a pseudo terminal. For usage in a real application, you
should check the return values of getpwuid() and ttyname().
.PP
.nf
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <utmp.h>
int main(int argc, char *argv[])
{
struct utmp entry;
system("echo before adding entry:;who");
entry.ut_type=USER_PROCESS;
entry.ut_pid=getpid();
strcpy(entry.ut_line,ttyname(0)+strlen("/dev/"));
/* only correct for ptys named /dev/tty[pqr][0-9a-z] */
strcpy(entry.ut_id,ttyname(0)+strlen("/dev/tty"));
time(&entry.ut_time);
strcpy(entry.ut_user,getpwuid(getuid())->pw_name);
memset(entry.ut_host,0,UT_HOSTSIZE);
entry.ut_addr=0;
setutent();
pututline(&entry);
system("echo after adding entry:;who");
entry.ut_type=DEAD_PROCESS;
memset(entry.ut_line,0,UT_LINESIZE);
entry.ut_time=0;
memset(entry.ut_user,0,UT_NAMESIZE);
setutent();
pututline(&entry);
system("echo after removing entry:;who");
endutent();
return 0;
}
.fi
.SH FILES
/var/run/utmp database of currently logged-in users
.br
/var/log/wtmp database of past user logins
.SH "CONFORMING TO"
XPG 2, SVID 2, Linux FSSTND 1.2
.SH "SEE ALSO"
\fButmp\fP(5)
|