mount_setattr.2: Minor tweaks to Christian's patch
[man-pages.git] / man3 / login.3
blobb840ad6be4105a595d88fed75c1712b4417e8cd2
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 2021-03-22 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 login, logout \- write utmp and wtmp entries
28 .SH SYNOPSIS
29 .nf
30 .B #include <utmp.h>
31 .PP
32 .BI "void login(const struct utmp *" ut );
33 .BI "int logout(const char *" ut_line );
34 .fi
35 .PP
36 Link with \fI\-lutil\fP.
37 .SH DESCRIPTION
38 The utmp file records who is currently using the system.
39 The wtmp file records all logins and logouts.
40 See
41 .BR utmp (5).
42 .PP
43 The function
44 .BR login ()
45 takes the supplied
46 .IR "struct utmp" ,
47 .IR ut ,
48 and writes it to both the utmp and the wtmp file.
49 .PP
50 The function
51 .BR logout ()
52 clears the entry in the utmp file again.
53 .SS GNU details
54 More precisely,
55 .BR login ()
56 takes the argument
57 .I ut
58 struct, fills the field
59 .I ut\->ut_type
60 (if there is such a field) with the value
61 .BR USER_PROCESS ,
62 and fills the field
63 .I ut\->ut_pid
64 (if there is such a field) with the process ID of the calling process.
65 Then it tries to fill the field
66 .IR ut\->ut_line .
67 It takes the first of
68 .IR stdin ,
69 .IR stdout ,
70 .I stderr
71 that is a terminal, and
72 stores the corresponding pathname minus a possible leading
73 .I /dev/
74 into this field, and then writes the struct to the utmp file.
75 On the other hand,
76 if no terminal name was found, this field is filled with "???"
77 and the struct is not written to the utmp file.
78 After this, the struct is written to the wtmp file.
79 .PP
80 The
81 .BR logout ()
82 function searches the utmp file for an entry matching the
83 .I ut_line
84 argument.
85 If a record is found, it is updated by zeroing out the
86 .I ut_name
87 and
88 .I ut_host
89 fields, updating the
90 .I ut_tv
91 timestamp field and setting
92 .I ut_type
93 (if there is such a field) to
94 .BR DEAD_PROCESS .
95 .SH RETURN VALUE
96 The
97 .BR logout ()
98 function returns 1 if the entry was successfully written to the
99 database, or 0 if an error occurred.
100 .SH FILES
102 .I /var/run/utmp
103 user accounting database, configured through
104 .B _PATH_UTMP
106 .I <paths.h>
108 .I /var/log/wtmp
109 user accounting log file, configured through
110 .B _PATH_WTMP
112 .I <paths.h>
113 .SH ATTRIBUTES
114 For an explanation of the terms used in this section, see
115 .BR attributes (7).
116 .ad l
119 allbox;
120 lb lb lbx
121 l l l.
122 Interface       Attribute       Value
124 .BR login (),
125 .BR logout ()
126 T}      Thread safety   T{
127 MT-Unsafe race:utent
128 sig:ALRM timer
133 .sp 1
134 In the above table,
135 .I utent
137 .I race:utent
138 signifies that if any of the functions
139 .BR setutent (3),
140 .BR getutent (3),
142 .BR endutent (3)
143 are used in parallel in different threads of a program,
144 then data races could occur.
145 .BR login ()
147 .BR logout ()
148 calls those functions,
149 so we use race:utent to remind users.
150 .SH CONFORMING TO
151 Not in POSIX.1.
152 Present on the BSDs.
153 .SH NOTES
154 Note that the
155 member
156 .I ut_user
158 .I struct utmp
159 is called
160 .I ut_name
161 in BSD.
162 Therefore,
163 .I ut_name
164 is defined as an alias for
165 .I ut_user
167 .IR <utmp.h> .
168 .SH SEE ALSO
169 .BR getutent (3),
170 .BR utmp (5)