]>
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 | .\" | |
97986708 | 28 | .TH TTYSLOT 3 2016-03-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 | |
cc4615cc | 32 | .BR "#include <unistd.h>" " /* on BSD-like systems, and Linux */" |
fea681da | 33 | .br |
80b50848 | 34 | .BR "#include <stdlib.h>" " /* on System V-like systems */" |
fea681da MK |
35 | .sp |
36 | .B "int ttyslot(void);" | |
cc4615cc MK |
37 | .sp |
38 | .in -4n | |
39 | Feature Test Macro Requirements for glibc (see | |
40 | .BR feature_test_macros (7)): | |
41 | .in | |
42 | .sp | |
43 | .ad l | |
44 | .BR ttyslot (): | |
f0644d82 | 45 | .RS 4 |
b40ec4cb MK |
46 | Since glibc 2.20: |
47 | _BSD_SOURCE || | |
48 | _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_\ <\ 500 | |
f0644d82 | 49 | .br |
b40ec4cb MK |
50 | Glibc 2.19 and earlier: |
51 | _DEFAULT_SOURCE || | |
52 | _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_\ <\ 500 | |
f0644d82 | 53 | .RE |
cc4615cc | 54 | .ad b |
fea681da MK |
55 | .SH DESCRIPTION |
56 | The legacy function | |
57 | .BR ttyslot () | |
58 | returns the index of the current user's entry in some file. | |
59 | .LP | |
c13182ef MK |
60 | Now "What file?" you ask. |
61 | Well, let's first look at some history. | |
73d8cece | 62 | .SS Ancient history |
fea681da MK |
63 | There used to be a file |
64 | .I /etc/ttys | |
b4112efb | 65 | in UNIX\ V6, that was read by the |
e8906093 | 66 | .BR init (1) |
fea681da MK |
67 | program to find out what to do with each terminal line. |
68 | Each line consisted of three characters. | |
f81fb444 MK |
69 | The first character was either \(aq0\(aq or \(aq1\(aq, |
70 | where \(aq0\(aq meant "ignore". | |
71 | The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8". | |
fea681da | 72 | The third character was an argument to |
d80b8255 | 73 | .BR getty (8) |
f81fb444 | 74 | indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying |
c13182ef MK |
75 | 110 baud). |
76 | Thus a typical line was "18\-". | |
f81fb444 | 77 | A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq, |
d9bfdb9c | 78 | signaling init, changing back again, and signaling init again. |
fea681da | 79 | .LP |
b4112efb | 80 | In UNIX\ V7 the format was changed: here the second character |
fea681da | 81 | was the argument to |
d80b8255 | 82 | .BR getty (8) |
f81fb444 MK |
83 | indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through |
84 | 300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter) | |
fea681da MK |
85 | while the rest of the line contained the name of the tty. |
86 | Thus a typical line was "14console". | |
87 | .LP | |
88 | Later systems have more elaborate syntax. | |
80b50848 | 89 | System V-like systems have |
fea681da MK |
90 | .I /etc/inittab |
91 | instead. | |
73d8cece | 92 | .SS Ancient history (2) |
fea681da MK |
93 | On the other hand, there is the file |
94 | .I /etc/utmp | |
c13182ef MK |
95 | listing the people currently logged in. |
96 | It is maintained by | |
49ec013c | 97 | .BR login (1). |
fea681da MK |
98 | It has a fixed size, and the appropriate index in the file was |
99 | determined by | |
49ec013c | 100 | .BR login (1) |
fea681da MK |
101 | using the |
102 | .BR ttyslot () | |
103 | call to find the number of the line in | |
0daa9e92 | 104 | .I /etc/ttys |
fea681da | 105 | (counting from 1). |
73d8cece | 106 | .SS The semantics of ttyslot |
fea681da MK |
107 | Thus, the function |
108 | .BR ttyslot () | |
a1ffe9f5 | 109 | returns the index of the controlling terminal of the calling process |
fea681da MK |
110 | in the file |
111 | .IR /etc/ttys , | |
112 | and that is (usually) the same as the index of the entry for the | |
113 | current user in the file | |
114 | .IR /etc/utmp . | |
115 | BSD still has the | |
116 | .I /etc/ttys | |
80b50848 | 117 | file, but System V-like systems do not, and hence cannot refer to it. |
fea681da MK |
118 | Thus, on such systems the documentation says that |
119 | .BR ttyslot () | |
120 | returns the current user's index in the user accounting data base. | |
47297adb | 121 | .SH RETURN VALUE |
fea681da MK |
122 | If successful, this function returns the slot number. |
123 | On error (e.g., if none of the file descriptors 0, 1 or 2 is | |
124 | associated with a terminal that occurs in this data base) | |
b4112efb | 125 | it returns 0 on UNIX\ V6 and V7 and BSD-like systems, |
80b50848 | 126 | but \-1 on System V-like systems. |
be05dcc7 | 127 | .SH ATTRIBUTES |
fad2b208 PH |
128 | For an explanation of the terms used in this section, see |
129 | .BR attributes (7). | |
130 | .TS | |
131 | allbox; | |
132 | lb lb lb | |
133 | l l l. | |
134 | Interface Attribute Value | |
135 | T{ | |
be05dcc7 | 136 | .BR ttyslot () |
fad2b208 PH |
137 | T} Thread safety MT-Unsafe |
138 | .TE | |
47297adb | 139 | .SH CONFORMING TO |
39ed8b54 | 140 | SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001. |
2b2581ee | 141 | SUSv2 requires \-1 on error. |
fea681da MK |
142 | .SH NOTES |
143 | The utmp file is found various places on various systems, such as | |
144 | .IR /etc/utmp , | |
145 | .IR /var/adm/utmp , | |
146 | .IR /var/run/utmp . | |
147 | .LP | |
148 | The glibc2 implementation of this function reads the file | |
149 | .BR _PATH_TTYS , | |
150 | defined in | |
151 | .I <ttyent.h> | |
c13182ef MK |
152 | as "/etc/ttys". |
153 | It returns 0 on error. | |
fea681da MK |
154 | Since Linux systems do not usually have "/etc/ttys", it will |
155 | always return 0. | |
156 | .LP | |
157 | Minix also has | |
158 | .IR fttyslot ( fd ). | |
889829be MK |
159 | .\" .SH HISTORY |
160 | .\" .BR ttyslot () | |
008f1ecc | 161 | .\" appeared in UNIX V7. |
47297adb | 162 | .SH SEE ALSO |
fea681da MK |
163 | .BR getttyent (3), |
164 | .BR ttyname (3), | |
165 | .BR utmp (5) |