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