]> git.saurik.com Git - apple/libc.git/blame - gen/endutxent.3
Libc-763.11.tar.gz
[apple/libc.git] / gen / endutxent.3
CommitLineData
1f2f436a 1.\" $NetBSD: endutxent.3,v 1.5 2008/04/30 13:10:50 martin Exp $
224c7076
A
2.\"
3.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Thomas Klausner.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
224c7076
A
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd June 29, 2006
31.Dt ENDUTXENT 3
32.Os
33.Sh NAME
34.Nm endutxent ,
35.Nm getutxent ,
36.Nm getutxid ,
37.Nm getutxline ,
38.Nm pututxline ,
39.Nm setutxent
40.Nd user accounting database functions
41.Sh LIBRARY
42.Lb libc
43.Sh SYNOPSIS
44.In utmpx.h
45.Ft void
46.Fn endutxent void
47.Ft struct utmpx *
48.Fn getutxent void
49.Ft struct utmpx *
50.Fn getutxid "const struct utmpx *id"
51.Ft struct utmpx *
52.Fn getutxline "const struct utmpx *line"
53.Ft struct utmpx *
54.Fn pututxline "const struct utmpx *utx"
55.Ft void
56.Fn setutxent void
57.Sh DESCRIPTION
58These functions provide access to the
59.Xr utmpx 5
60user accounting database.
61.Pp
62.Fn getutxent
63reads the next entry from the database;
64if the database was not yet open, it also opens it.
65.Fn setutxent
66resets the database, so that the next
67.Fn getutxent
68call will get the first entry.
69.Fn endutxent
70closes the database.
71.Pp
72.Fn getutxid
73returns the next entry of the type specified in its argument's
74.Va ut_type
75field, or
76.Dv NULL
77if none is found.
78.Fn getutxline
79returns the next
80.Dv LOGIN_PROCESS
81or
82.Dv USER_PROCESS
83entry which has the same name as specified in the
84.Va ut_line
85field, or
86.Dv NULL
87if no match is found.
88.Pp
89.Fn pututxline
90adds the argument
91.Xr utmpx 5
92entry line to the accounting database, replacing a previous entry for
93the same user if it exists.
94Only the superuser may write to the accounting database.
95.Ss The utmpx structure
96The
97.Nm utmpx
98structure has the following definition:
99.Pp
100.Bd -literal
101struct utmpx {
102 char ut_user[_UTX_USERSIZE]; /* login name */
103 char ut_id[_UTX_IDSIZE]; /* id */
104 char ut_line[_UTX_LINESIZE]; /* tty name */
105 pid_t ut_pid; /* process id creating the entry */
106 short ut_type; /* type of this entry */
107 struct timeval ut_tv; /* time entry was created */
108 char ut_host[_UTX_HOSTSIZE]; /* host name */
109 __uint32_t ut_pad[16]; /* reserved for future use */
110};
111.Ed
112.Pp
113Valid entries for
114.Fa ut_type
115are:
116.Bl -tag -width ".Dv LOGIN_PROCESSXX" -compact -offset indent
117.It Dv BOOT_TIME
118Time of a system boot.
119.It Dv DEAD_PROCESS
120A session leader exited.
121.It Dv EMPTY
122No valid user accounting information.
123.It Dv INIT_PROCESS
124A process spawned by
125.Xr init 8 .
126.It Dv LOGIN_PROCESS
127The session leader of a logged-in user.
128.It Dv NEW_TIME
129Time after system clock change.
130.It Dv OLD_TIME
131Time before system clock change.
132.It Dv RUN_LVL
133Run level.
134Provided for compatibility, not used.
135.It Dv USER_PROCESS
136A user process.
137.It Dv SHUTDOWN_TIME
138Time of system shutdown (extension to the standards).
139.El
140.Pp
141For each value of
142.Fa ut_type ,
143the other fields with meaningful values are as follows:
144.Bl -tag -width ".Dv LOGIN_PROCESSXX" -compact -offset indent
145.It Dv BOOT_TIME
146.Fa ut_tv
147.It Dv DEAD_PROCESS
148.Fa ut_id ,
149.Fa ut_pid ,
150.Fa ut_tv
151.It Dv EMPTY
152(no others)
153.It Dv INIT_PROCESS
154.Fa ut_id ,
155.Fa ut_pid ,
156.Fa ut_tv
157.It Dv LOGIN_PROCESS
158.Fa ut_id ,
159.Fa ut_user
160(implementation-defined name of the login process),
161.Fa ut_pid ,
162.Fa ut_tv
163.It Dv NEW_TIME
164.Fa ut_tv
165.It Dv OLD_TIME
166.Fa ut_tv
167.It Dv RUN_LVL
168(no used)
169.It Dv USER_PROCESS
170.Fa ut_id ,
171.Fa ut_user
172(login name of the user),
173.Fa ut_line ,
174.Fa ut_pid ,
175.Fa ut_host
176(hostname of remote user)
177.Fa ut_tv
178.It Dv SHUTDOWN_TIME
179.Fa ut_tv
180.El
181.Ss Other extensions to the standards
182The
1f2f436a 183.Fa ut_type
224c7076
A
184value may also be OR-ed with the following masks:
185.Bl -tag -width XXXX -compact -offset indent
186.It Dv UTMPX_AUTOFILL_MASK
1f2f436a 187Depending on the main part of
224c7076
A
188.Fa ut_type
189value, other fields are automatically filled in (as specified in the
190meaningful fields table above).
191In particular, the
192.Fa ut_id
193field will be set using the convention of the last four characters of the
194.Fa ut_line
195field (itself filled in automatically from the tty name of the device connected
196to the standard input, output or error, whichever is available).
197Note that it is more efficient to fill in as many values as are already
198available beforehand, rather than have then automatically filled in.
199.It Dv UTMPX_DEAD_IF_CORRESPONDING_MASK
200When
201.Fa ut_type
202value is
203.Dv DEAD_PROCESS, a call to
204.Fn pututxline
205will succeed only if a corresponding entry already exists with a
206.Fa ut_type
207value of
208.Dv USER_PROCESS .
209.El
210.Pp
211Note that the above mask values do not show up in any file format, or in
212any subsequent reads of the data.
213.Pp
214To support
215.Pa wtmpx
216and
217.Pa lastlogx
218equivalent capability,
219.Fn pututxline
220automatically writes to the appropriate files.
221Additional APIs to read these files is available in
222.Xr endutxent_wtmp 3
223and
224.Xr getlastlogx 3 .
225.Ss Backward compatibility
226Successful calls to
227.Fn pututxline
228will automatically write equivalent entries into the
229.Pa utmp ,
230.Pa wtmp
231and
232.Pa lastlog
233files.
234Programs that read these old files should work as expected.
235However, directly writing to these files does not make corresponding
236entries in
237.Pa utmpx
238and the
239.Pa wtmpx
240and
241.Pa lastlogx
242equivalent files, so such write-access is deprecated.
243.Sh RETURN VALUES
244.Fn getutxent
245returns the next entry, or
246.Dv NULL
247on failure (end of database or problems reading from the database).
248.Fn getutxid
249and
250.Fn getutxline
251return the matching structure on success, or
252.Dv NULL
253if no match was found.
254.Pp
255.Fn pututxline
256returns the structure that was successfully written, or
257.Dv NULL
258is returned and the global variable
259.Va errno
260is set to indicate the error.
261.Sh ERRORS
262No errors are defined for the
263.Fn endutxent ,
264.Fn getutxent ,
265.Fn getutxid ,
266.Fn getutxline ,
267and
268.Fn setutxent
269functions.
270.Pp
271The
272.Fn pututxline
273function may fail if:
274.Bl -tag -width Er
275.It Bq Er EPERM
276The process does not have appropriate privileges.
277.It Bq Er EINVAL
278The
279.Dv UTMPX_DEAD_IF_CORRESPONDING_MASK
280flags was specified along with
281.Dv DEAD_PROCESS ,
282but no corresponding entry with
283.Dv USER_PROCESS
284was found.
285.El
286.Pp
287Other errors may be returned if
288.Dv UTMPX_AUTOFILL_MASK
289was specified, and a field could not be auto-filled.
290.Sh SEE ALSO
291.Xr endutxent_wtmp 3 ,
292.Xr getlastlogx 3 ,
293.Xr utmpx 5
294.Sh STANDARDS
295The
296.Fn endutxent ,
297.Fn getutxent ,
298.Fn getutxid ,
299.Fn getutxline ,
300.Fn pututxline ,
301.Fn setutxent
302all conform to
303.St -p1003.1-2001
304(XSI extension), and previously to
305.St -xpg4.2 .
306The fields
307.Fa ut_user ,
308.Fa ut_id ,
309.Fa ut_line ,
310.Fa ut_pid ,
311.Fa ut_type ,
312and
313.Fa ut_tv
314conform to
315.St -p1003.1-2001
316(XSI extension), and previously to
317.St -xpg4.2 .
318.\" .Fa ut_host ,
319.\" .Fa ut_session ,
320.\" .Fa ut_exit ,
321.\" and
322.\" .Fa ut_ss
323.\" are from
324.\" SVR3/4?
325.\" .Dv RUN_LVL
326.\" is for compatibility with
327.\" what exactly?
328.\" .Sh HISTORY
329.\" The
330.\" .Nm utmpx ,
331.\" .Nm wtmpx ,
332.\" and
333.\" .Nm lastlogx
334.\" files first appeared in
335.\" SVR3? 4?