]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl> |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
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. | |
c13182ef | 12 | .\" |
fea681da MK |
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. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" This replaces an earlier man page written by Walter Harms | |
26 | .\" <walter.harms@informatik.uni-oldenburg.de>. | |
27 | .\" | |
4b8c67d9 | 28 | .TH TTYSLOT 3 2017-09-15 "GNU" "Linux Programmer's Manual" |
fea681da MK |
29 | .SH NAME |
30 | ttyslot \- find the slot of the current user's terminal in some file | |
31 | .SH SYNOPSIS | |
f8c8a903 | 32 | .BR "#include <unistd.h>" " /See NOTES */" |
68e4db0a | 33 | .PP |
fea681da | 34 | .B "int ttyslot(void);" |
68e4db0a | 35 | .PP |
cc4615cc MK |
36 | .in -4n |
37 | Feature Test Macro Requirements for glibc (see | |
38 | .BR feature_test_macros (7)): | |
39 | .in | |
68e4db0a | 40 | .PP |
cc4615cc MK |
41 | .ad l |
42 | .BR ttyslot (): | |
f0644d82 | 43 | .RS 4 |
f30306c4 MK |
44 | Since glibc 2.24: |
45 | _DEFAULT_SOURCE | |
46 | .br | |
47 | From glibc 2.20 to 2.23: | |
3f1873a8 | 48 | _DEFAULT_SOURCE || |
2ca6d534 | 49 | _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE\ <\ 500 |
f0644d82 | 50 | .br |
b40ec4cb | 51 | Glibc 2.19 and earlier: |
3f1873a8 | 52 | _BSD_SOURCE || |
2ca6d534 | 53 | _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE\ <\ 500 |
f0644d82 | 54 | .RE |
cc4615cc | 55 | .ad b |
fea681da MK |
56 | .SH DESCRIPTION |
57 | The legacy function | |
58 | .BR ttyslot () | |
59 | returns the index of the current user's entry in some file. | |
dd3568a1 | 60 | .PP |
c13182ef MK |
61 | Now "What file?" you ask. |
62 | Well, let's first look at some history. | |
73d8cece | 63 | .SS Ancient history |
fea681da MK |
64 | There used to be a file |
65 | .I /etc/ttys | |
b4112efb | 66 | in UNIX\ V6, that was read by the |
e8906093 | 67 | .BR init (1) |
fea681da MK |
68 | program to find out what to do with each terminal line. |
69 | Each line consisted of three characters. | |
f81fb444 MK |
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". | |
fea681da | 73 | The third character was an argument to |
d80b8255 | 74 | .BR getty (8) |
f81fb444 | 75 | indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying |
c13182ef MK |
76 | 110 baud). |
77 | Thus a typical line was "18\-". | |
f81fb444 | 78 | A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq, |
d9bfdb9c | 79 | signaling init, changing back again, and signaling init again. |
dd3568a1 | 80 | .PP |
b4112efb | 81 | In UNIX\ V7 the format was changed: here the second character |
fea681da | 82 | was the argument to |
d80b8255 | 83 | .BR getty (8) |
f81fb444 MK |
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) | |
fea681da MK |
86 | while the rest of the line contained the name of the tty. |
87 | Thus a typical line was "14console". | |
dd3568a1 | 88 | .PP |
fea681da | 89 | Later systems have more elaborate syntax. |
80b50848 | 90 | System V-like systems have |
fea681da MK |
91 | .I /etc/inittab |
92 | instead. | |
73d8cece | 93 | .SS Ancient history (2) |
fea681da MK |
94 | On the other hand, there is the file |
95 | .I /etc/utmp | |
c13182ef MK |
96 | listing the people currently logged in. |
97 | It is maintained by | |
49ec013c | 98 | .BR login (1). |
fea681da MK |
99 | It has a fixed size, and the appropriate index in the file was |
100 | determined by | |
49ec013c | 101 | .BR login (1) |
fea681da MK |
102 | using the |
103 | .BR ttyslot () | |
104 | call to find the number of the line in | |
0daa9e92 | 105 | .I /etc/ttys |
fea681da | 106 | (counting from 1). |
73d8cece | 107 | .SS The semantics of ttyslot |
fea681da MK |
108 | Thus, the function |
109 | .BR ttyslot () | |
a1ffe9f5 | 110 | returns the index of the controlling terminal of the calling process |
fea681da MK |
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 | |
80b50848 | 118 | file, but System V-like systems do not, and hence cannot refer to it. |
fea681da MK |
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. | |
47297adb | 122 | .SH RETURN VALUE |
fea681da MK |
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) | |
b4112efb | 126 | it returns 0 on UNIX\ V6 and V7 and BSD-like systems, |
80b50848 | 127 | but \-1 on System V-like systems. |
be05dcc7 | 128 | .SH ATTRIBUTES |
fad2b208 PH |
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{ | |
be05dcc7 | 137 | .BR ttyslot () |
fad2b208 PH |
138 | T} Thread safety MT-Unsafe |
139 | .TE | |
47297adb | 140 | .SH CONFORMING TO |
39ed8b54 | 141 | SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001. |
2b2581ee | 142 | SUSv2 requires \-1 on error. |
fea681da | 143 | .SH NOTES |
62dc68ae | 144 | The utmp file is found in various places on various systems, such as |
fea681da MK |
145 | .IR /etc/utmp , |
146 | .IR /var/adm/utmp , | |
147 | .IR /var/run/utmp . | |
dd3568a1 | 148 | .PP |
fea681da MK |
149 | The glibc2 implementation of this function reads the file |
150 | .BR _PATH_TTYS , | |
151 | defined in | |
152 | .I <ttyent.h> | |
c13182ef MK |
153 | as "/etc/ttys". |
154 | It returns 0 on error. | |
fea681da MK |
155 | Since Linux systems do not usually have "/etc/ttys", it will |
156 | always return 0. | |
f8c8a903 MK |
157 | .PP |
158 | On BSD-like systems and Linux, the declaration of | |
159 | .BR ttyslot () | |
160 | is provided by | |
161 | .IR <unistd.h> . | |
c52ba260 | 162 | On System V-like systems, the declaration is provided by |
f8c8a903 MK |
163 | .IR <stdlib.h> . |
164 | Since glibc 2.24, | |
d8a86e74 | 165 | .I <stdlib.h> |
f8c8a903 MK |
166 | also provides the declaration with the following |
167 | feature test macro definitions: | |
168 | .PP | |
f8c8a903 | 169 | .in +4n |
b8302363 | 170 | .EX |
f8c8a903 MK |
171 | (_XOPEN_SOURCE >= 500 || |
172 | (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED)) | |
173 | && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) | |
b8302363 | 174 | .EE |
e646a1ba | 175 | .in |
f8c8a903 | 176 | .PP |
fea681da MK |
177 | Minix also has |
178 | .IR fttyslot ( fd ). | |
889829be MK |
179 | .\" .SH HISTORY |
180 | .\" .BR ttyslot () | |
008f1ecc | 181 | .\" appeared in UNIX V7. |
47297adb | 182 | .SH SEE ALSO |
fea681da MK |
183 | .BR getttyent (3), |
184 | .BR ttyname (3), | |
185 | .BR utmp (5) |