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