1login(3)                   Library Functions Manual                   login(3)
2
3
4

NAME

6       login, logout - write utmp and wtmp entries
7

LIBRARY

9       System utilities library (libutil, -lutil)
10

SYNOPSIS

12       #include <utmp.h>
13
14       void login(const struct utmp *ut);
15       int logout(const char *ut_line);
16

DESCRIPTION

18       The utmp file records who is currently using the system.  The wtmp file
19       records all logins and logouts.  See utmp(5).
20
21       The function login() takes the supplied struct utmp, ut, and writes  it
22       to both the utmp and the wtmp file.
23
24       The function logout() clears the entry in the utmp file again.
25
26   GNU details
27       More  precisely,  login() takes the argument ut struct, fills the field
28       ut->ut_type (if there is such a field) with the value USER_PROCESS, and
29       fills  the field ut->ut_pid (if there is such a field) with the process
30       ID  of  the  calling  process.   Then  it  tries  to  fill  the   field
31       ut->ut_line.   It  takes  the  first of stdin, stdout, stderr that is a
32       terminal, and stores the corresponding pathname minus a possible  lead‐
33       ing /dev/ into this field, and then writes the struct to the utmp file.
34       On the other hand, if no terminal name was found, this field is  filled
35       with  "???"   and  the  struct  is not written to the utmp file.  After
36       this, the struct is written to the wtmp file.
37
38       The logout() function searches the utmp file for an entry matching  the
39       ut_line  argument.   If a record is found, it is updated by zeroing out
40       the ut_name and ut_host fields, updating the ut_tv timestamp field  and
41       setting ut_type (if there is such a field) to DEAD_PROCESS.
42

RETURN VALUE

44       The  logout()  function returns 1 if the entry was successfully written
45       to the database, or 0 if an error occurred.
46

FILES

48       /var/run/utmp
49              user  accounting  database,  configured  through  _PATH_UTMP  in
50              <paths.h>
51
52       /var/log/wtmp
53              user  accounting  log  file,  configured  through  _PATH_WTMP in
54              <paths.h>
55

ATTRIBUTES

57       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
58       tributes(7).
59
60       ┌──────────────────┬───────────────┬───────────────────────────────────┐
61Interface         Attribute     Value                             
62       ├──────────────────┼───────────────┼───────────────────────────────────┤
63login(), logout() │ Thread safety │ MT-Unsafe race:utent sig:ALRM     │
64       │                  │               │ timer                             │
65       └──────────────────┴───────────────┴───────────────────────────────────┘
66       In the above table, utent in race:utent signifies that if  any  of  the
67       functions setutent(3), getutent(3), or endutent(3) are used in parallel
68       in different threads of a program, then data races  could  occur.   lo‐
69       gin()  and  logout() calls those functions, so we use race:utent to re‐
70       mind users.
71

VERSIONS

73       The member ut_user of struct utmp is called ut_name in BSD.  Therefore,
74       ut_name is defined as an alias for ut_user in <utmp.h>.
75

STANDARDS

77       BSD.
78

SEE ALSO

80       getutent(3), utmp(5)
81
82
83
84Linux man-pages 6.04              2023-03-30                          login(3)
Impressum