]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/login.3
share/mk/: distcheck: Run 'check' after 'build'
[thirdparty/man-pages.git] / man3 / login.3
1 .\" Derived from text written by Martin Schulze (or taken from glibc.info)
2 .\" and text written by Paul Thompson - both copyright 2002.
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .TH LOGIN 3 2017-09-15 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 login, logout \- write utmp and wtmp entries
28 .SH SYNOPSIS
29 .B #include <utmp.h>
30 .PP
31 .BI "void login(const struct utmp *" ut );
32 .PP
33 .BI "int logout(const char *" ut_line );
34 .PP
35 Link with \fI\-lutil\fP.
36 .SH DESCRIPTION
37 The utmp file records who is currently using the system.
38 The wtmp file records all logins and logouts.
39 See
40 .BR utmp (5).
41 .PP
42 The function
43 .BR login ()
44 takes the supplied
45 .IR "struct utmp" ,
46 .IR ut ,
47 and writes it to both the utmp and the wtmp file.
48 .PP
49 The function
50 .BR logout ()
51 clears the entry in the utmp file again.
52 .SS GNU details
53 More precisely,
54 .BR login ()
55 takes the argument
56 .I ut
57 struct, fills the field
58 .I ut\->ut_type
59 (if there is such a field) with the value
60 .BR USER_PROCESS ,
61 and fills the field
62 .I ut\->ut_pid
63 (if there is such a field) with the process ID of the calling process.
64 Then it tries to fill the field
65 .IR ut\->ut_line .
66 It takes the first of
67 .IR stdin ,
68 .IR stdout ,
69 .I stderr
70 that is a terminal, and
71 stores the corresponding pathname minus a possible leading
72 .I /dev/
73 into this field, and then writes the struct to the utmp file.
74 On the other hand,
75 if no terminal name was found, this field is filled with "???"
76 and the struct is not written to the utmp file.
77 After this, the struct is written to the wtmp file.
78 .PP
79 The
80 .BR logout ()
81 function searches the utmp file for an entry matching the
82 .I ut_line
83 argument.
84 If a record is found, it is updated by zeroing out the
85 .I ut_name
86 and
87 .I ut_host
88 fields, updating the
89 .I ut_tv
90 timestamp field and setting
91 .I ut_type
92 (if there is such a field) to
93 .BR DEAD_PROCESS .
94 .SH RETURN VALUE
95 The
96 .BR logout ()
97 function returns 1 if the entry was successfully written to the
98 database, or 0 if an error occurred.
99 .SH FILES
100 .TP
101 .I /var/run/utmp
102 user accounting database, configured through
103 .B _PATH_UTMP
104 in
105 .I <paths.h>
106 .TP
107 .I /var/log/wtmp
108 user accounting log file, configured through
109 .B _PATH_WTMP
110 in
111 .I <paths.h>
112 .SH ATTRIBUTES
113 For an explanation of the terms used in this section, see
114 .BR attributes (7).
115 .TS
116 allbox;
117 lb lb lbw20
118 l l l.
119 Interface Attribute Value
120 T{
121 .BR login (),
122 .br
123 .BR logout ()
124 T} Thread safety T{
125 MT-Unsafe race:utent
126 .br
127 sig:ALRM timer
128 T}
129 .TE
130 .sp 1
131 In the above table,
132 .I utent
133 in
134 .I race:utent
135 signifies that if any of the functions
136 .BR setutent (3),
137 .BR getutent (3),
138 or
139 .BR endutent (3)
140 are used in parallel in different threads of a program,
141 then data races could occur.
142 .BR login ()
143 and
144 .BR logout ()
145 calls those functions,
146 so we use race:utent to remind users.
147 .SH CONFORMING TO
148 Not in POSIX.1.
149 Present on the BSDs.
150 .SH NOTES
151 Note that the
152 member
153 .I ut_user
154 of
155 .I struct utmp
156 is called
157 .I ut_name
158 in BSD.
159 Therefore,
160 .I ut_name
161 is defined as an alias for
162 .I ut_user
163 in
164 .IR <utmp.h> .
165 .SH SEE ALSO
166 .BR getutent (3),
167 .BR utmp (5)