]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/ttyslot.3
man*/: srcfix (Use .P instead of .PP or .LP)
[thirdparty/man-pages.git] / man3 / ttyslot.3
1 '\" t
2 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" This replaces an earlier man page written by Walter Harms
7 .\" <walter.harms@informatik.uni-oldenburg.de>.
8 .\"
9 .TH ttyslot 3 (date) "Linux man-pages (unreleased)"
10 .SH NAME
11 ttyslot \- find the slot of the current user's terminal in some file
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .BR "#include <unistd.h>" " /* See NOTES */"
18 .P
19 .B "int ttyslot(void);"
20 .fi
21 .P
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .P
27 .BR ttyslot ():
28 .nf
29 Since glibc 2.24:
30 _DEFAULT_SOURCE
31 From glibc 2.20 to glibc 2.23:
32 _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
33 glibc 2.19 and earlier:
34 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
35 .fi
36 .SH DESCRIPTION
37 The legacy function
38 .BR ttyslot ()
39 returns the index of the current user's entry in some file.
40 .P
41 Now "What file?" you ask.
42 Well, let's first look at some history.
43 .SS Ancient history
44 There used to be a file
45 .I /etc/ttys
46 in UNIX\ V6, that was read by the
47 .BR init (1)
48 program to find out what to do with each terminal line.
49 Each line consisted of three characters.
50 The first character was either \[aq]0\[aq] or \[aq]1\[aq],
51 where \[aq]0\[aq] meant "ignore".
52 The second character denoted the terminal: \[aq]8\[aq] stood for "/dev/tty8".
53 The third character was an argument to
54 .BR getty (8)
55 indicating the sequence of line speeds to try (\[aq]\-\[aq] was: start trying
56 110 baud).
57 Thus a typical line was "18\-".
58 A hang on some line was solved by changing the \[aq]1\[aq] to a \[aq]0\[aq],
59 signaling init, changing back again, and signaling init again.
60 .P
61 In UNIX\ V7 the format was changed: here the second character
62 was the argument to
63 .BR getty (8)
64 indicating the sequence of line speeds to try (\[aq]0\[aq] was: cycle through
65 300-1200-150-110 baud; \[aq]4\[aq] was for the on-line console DECwriter)
66 while the rest of the line contained the name of the tty.
67 Thus a typical line was "14console".
68 .P
69 Later systems have more elaborate syntax.
70 System V-like systems have
71 .I /etc/inittab
72 instead.
73 .SS Ancient history (2)
74 On the other hand, there is the file
75 .I /etc/utmp
76 listing the people currently logged in.
77 It is maintained by
78 .BR login (1).
79 It has a fixed size, and the appropriate index in the file was
80 determined by
81 .BR login (1)
82 using the
83 .BR ttyslot ()
84 call to find the number of the line in
85 .I /etc/ttys
86 (counting from 1).
87 .SS The semantics of ttyslot
88 Thus, the function
89 .BR ttyslot ()
90 returns the index of the controlling terminal of the calling process
91 in the file
92 .IR /etc/ttys ,
93 and that is (usually) the same as the index of the entry for the
94 current user in the file
95 .IR /etc/utmp .
96 BSD still has the
97 .I /etc/ttys
98 file, but System V-like systems do not, and hence cannot refer to it.
99 Thus, on such systems the documentation says that
100 .BR ttyslot ()
101 returns the current user's index in the user accounting data base.
102 .SH RETURN VALUE
103 If successful, this function returns the slot number.
104 On error (e.g., if none of the file descriptors 0, 1, or 2 is
105 associated with a terminal that occurs in this data base)
106 it returns 0 on UNIX\ V6 and V7 and BSD-like systems,
107 but \-1 on System V-like systems.
108 .SH ATTRIBUTES
109 For an explanation of the terms used in this section, see
110 .BR attributes (7).
111 .TS
112 allbox;
113 lbx lb lb
114 l l l.
115 Interface Attribute Value
116 T{
117 .na
118 .nh
119 .BR ttyslot ()
120 T} Thread safety MT-Unsafe
121 .TE
122 .SH VERSIONS
123 The utmp file is found in various places on various systems, such as
124 .IR /etc/utmp ,
125 .IR /var/adm/utmp ,
126 .IR /var/run/utmp .
127 .SH STANDARDS
128 None.
129 .SH HISTORY
130 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
131 SUSv2 requires \-1 on error.
132 .P
133 The glibc2 implementation of this function reads the file
134 .BR _PATH_TTYS ,
135 defined in
136 .I <ttyent.h>
137 as "/etc/ttys".
138 It returns 0 on error.
139 Since Linux systems do not usually have "/etc/ttys", it will
140 always return 0.
141 .P
142 On BSD-like systems and Linux, the declaration of
143 .BR ttyslot ()
144 is provided by
145 .IR <unistd.h> .
146 On System V-like systems, the declaration is provided by
147 .IR <stdlib.h> .
148 Since glibc 2.24,
149 .I <stdlib.h>
150 also provides the declaration with the following
151 feature test macro definitions:
152 .P
153 .in +4n
154 .EX
155 (_XOPEN_SOURCE >= 500 ||
156 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
157 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
158 .EE
159 .in
160 .P
161 Minix also has
162 .IR fttyslot ( fd ).
163 .\" .SH HISTORY
164 .\" .BR ttyslot ()
165 .\" appeared in UNIX V7.
166 .SH SEE ALSO
167 .BR getttyent (3),
168 .BR ttyname (3),
169 .BR utmp (5)