]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl> |
2 | .\" | |
3 | .\" Permission is granted to make and distribute verbatim copies of this | |
4 | .\" manual provided the copyright notice and this permission notice are | |
5 | .\" preserved on all copies. | |
6 | .\" | |
7 | .\" Permission is granted to copy and distribute modified versions of this | |
8 | .\" manual under the conditions for verbatim copying, provided that the | |
9 | .\" entire resulting derived work is distributed under the terms of a | |
10 | .\" permission notice identical to this one. | |
c13182ef | 11 | .\" |
fea681da MK |
12 | .\" Since the Linux kernel and libraries are constantly changing, this |
13 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
14 | .\" responsibility for errors or omissions, or for damages resulting from | |
15 | .\" the use of the information contained herein. The author(s) may not | |
16 | .\" have taken the same level of care in the production of this manual, | |
17 | .\" which is licensed free of charge, as they might when working | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
23 | .\" This replaces an earlier man page written by Walter Harms | |
24 | .\" <walter.harms@informatik.uni-oldenburg.de>. | |
25 | .\" | |
26 | .TH TTYSLOT 3 2002-07-20 "GNU" "Linux Programmer's Manual" | |
27 | .SH NAME | |
28 | ttyslot \- find the slot of the current user's terminal in some file | |
29 | .SH SYNOPSIS | |
30 | .sp | |
31 | .BR "#include <unistd.h>" " /* on BSD-like systems */" | |
32 | .br | |
80b50848 | 33 | .BR "#include <stdlib.h>" " /* on System V-like systems */" |
fea681da MK |
34 | .sp |
35 | .B "int ttyslot(void);" | |
36 | .SH DESCRIPTION | |
37 | The legacy function | |
38 | .BR ttyslot () | |
39 | returns the index of the current user's entry in some file. | |
40 | .LP | |
c13182ef MK |
41 | Now "What file?" you ask. |
42 | Well, let's first look at some history. | |
fea681da MK |
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 (8) | |
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 '0' or '1', where '0' meant "ignore". | |
51 | The second character denoted the terminal: '8' stood for "/dev/tty8". | |
52 | The third character was an argument to | |
53 | .BR getty (8) | |
8c383102 | 54 | indicating the sequence of line speeds to try ('\-' was: start trying |
c13182ef MK |
55 | 110 baud). |
56 | Thus a typical line was "18\-". | |
fea681da MK |
57 | A hang on some line was solved by changing the '1' to a '0', |
58 | signalling init, changing back again, and signalling init again. | |
59 | .LP | |
60 | In Unix V7 the format was changed: here the second character | |
61 | was the argument to | |
62 | .BR getty (8) | |
63 | indicating the sequence of line speeds to try ('0' was: cycle through | |
64 | 300-1200-150-110 baud; '4' was for the on-line console DECwriter) | |
65 | while the rest of the line contained the name of the tty. | |
66 | Thus a typical line was "14console". | |
67 | .LP | |
68 | Later systems have more elaborate syntax. | |
80b50848 | 69 | System V-like systems have |
fea681da MK |
70 | .I /etc/inittab |
71 | instead. | |
72 | .SS "Ancient History (2)" | |
73 | On the other hand, there is the file | |
74 | .I /etc/utmp | |
c13182ef MK |
75 | listing the people currently logged in. |
76 | It is maintained by | |
fea681da MK |
77 | .BR login (8). |
78 | It has a fixed size, and the appropriate index in the file was | |
79 | determined by | |
80 | .BR login (8) | |
81 | using the | |
82 | .BR ttyslot () | |
83 | call to find the number of the line in | |
84 | .IR /etc/ttys | |
85 | (counting from 1). | |
86 | .SS "The semantics of ttyslot" | |
87 | Thus, the function | |
88 | .BR ttyslot () | |
89 | returns the index of the controlling terminal of the current process | |
90 | in the file | |
91 | .IR /etc/ttys , | |
92 | and that is (usually) the same as the index of the entry for the | |
93 | current user in the file | |
94 | .IR /etc/utmp . | |
95 | BSD still has the | |
96 | .I /etc/ttys | |
80b50848 | 97 | file, but System V-like systems do not, and hence cannot refer to it. |
fea681da MK |
98 | Thus, on such systems the documentation says that |
99 | .BR ttyslot () | |
100 | returns the current user's index in the user accounting data base. | |
101 | .SH "RETURN VALUE" | |
102 | If successful, this function returns the slot number. | |
103 | On error (e.g., if none of the file descriptors 0, 1 or 2 is | |
104 | associated with a terminal that occurs in this data base) | |
105 | it returns 0 on Unix V6 and V7 and BSD-like systems, | |
80b50848 | 106 | but \-1 on System V-like systems. |
2b2581ee MK |
107 | .SH "CONFORMING TO" |
108 | SUSv1; marked as LECACY in SUSv2; removed in POSIX.1-2001. | |
109 | SUSv2 requires \-1 on error. | |
fea681da MK |
110 | .SH NOTES |
111 | The utmp file is found various places on various systems, such as | |
112 | .IR /etc/utmp , | |
113 | .IR /var/adm/utmp , | |
114 | .IR /var/run/utmp . | |
115 | .LP | |
116 | The glibc2 implementation of this function reads the file | |
117 | .BR _PATH_TTYS , | |
118 | defined in | |
119 | .I <ttyent.h> | |
c13182ef MK |
120 | as "/etc/ttys". |
121 | It returns 0 on error. | |
fea681da MK |
122 | Since Linux systems do not usually have "/etc/ttys", it will |
123 | always return 0. | |
124 | .LP | |
125 | Minix also has | |
126 | .IR fttyslot ( fd ). | |
889829be MK |
127 | .\" .SH HISTORY |
128 | .\" .BR ttyslot () | |
129 | .\" appeared in Unix V7. | |
fea681da MK |
130 | .SH "SEE ALSO" |
131 | .BR getttyent (3), | |
132 | .BR ttyname (3), | |
133 | .BR utmp (5) |