]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/ttyslot.3
Replace "SysV" by "System V"
[thirdparty/man-pages.git] / man3 / ttyslot.3
CommitLineData
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.
11.\"
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.
19.\"
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
28ttyslot \- 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
33.BR "#include <stdlib.h>" " /* on SYSV-like systems */"
34.sp
35.B "int ttyslot(void);"
36.SH DESCRIPTION
37The legacy function
38.BR ttyslot ()
39returns the index of the current user's entry in some file.
40.LP
41Now "What file?" you ask. Well, let's first look at some history.
42.SS "Ancient History"
43There used to be a file
44.I /etc/ttys
45in Unix V6, that was read by the
46.BR init (8)
47program to find out what to do with each terminal line.
48Each line consisted of three characters.
49The first character was either '0' or '1', where '0' meant "ignore".
50The second character denoted the terminal: '8' stood for "/dev/tty8".
51The third character was an argument to
52.BR getty (8)
8c383102
MK
53indicating the sequence of line speeds to try ('\-' was: start trying
54110 baud). Thus a typical line was "18\-".
fea681da
MK
55A hang on some line was solved by changing the '1' to a '0',
56signalling init, changing back again, and signalling init again.
57.LP
58In Unix V7 the format was changed: here the second character
59was the argument to
60.BR getty (8)
61indicating the sequence of line speeds to try ('0' was: cycle through
62300-1200-150-110 baud; '4' was for the on-line console DECwriter)
63while the rest of the line contained the name of the tty.
64Thus a typical line was "14console".
65.LP
66Later systems have more elaborate syntax.
67SYSV-like systems have
68.I /etc/inittab
69instead.
70.SS "Ancient History (2)"
71On the other hand, there is the file
72.I /etc/utmp
73listing the people currently logged in. It is maintained by
74.BR login (8).
75It has a fixed size, and the appropriate index in the file was
76determined by
77.BR login (8)
78using the
79.BR ttyslot ()
80call to find the number of the line in
81.IR /etc/ttys
82(counting from 1).
83.SS "The semantics of ttyslot"
84Thus, the function
85.BR ttyslot ()
86returns the index of the controlling terminal of the current process
87in the file
88.IR /etc/ttys ,
89and that is (usually) the same as the index of the entry for the
90current user in the file
91.IR /etc/utmp .
92BSD still has the
93.I /etc/ttys
94file, but SYSV-like systems do not, and hence cannot refer to it.
95Thus, on such systems the documentation says that
96.BR ttyslot ()
97returns the current user's index in the user accounting data base.
98.SH "RETURN VALUE"
99If successful, this function returns the slot number.
100On error (e.g., if none of the file descriptors 0, 1 or 2 is
101associated with a terminal that occurs in this data base)
102it returns 0 on Unix V6 and V7 and BSD-like systems,
103but \-1 on SYSV-like systems.
104.SH NOTES
105The utmp file is found various places on various systems, such as
106.IR /etc/utmp ,
107.IR /var/adm/utmp ,
108.IR /var/run/utmp .
109.LP
110The glibc2 implementation of this function reads the file
111.BR _PATH_TTYS ,
112defined in
113.I <ttyent.h>
114as "/etc/ttys". It returns 0 on error.
115Since Linux systems do not usually have "/etc/ttys", it will
116always return 0.
117.LP
118Minix also has
119.IR fttyslot ( fd ).
120.SH HISTORY
121.BR ttyslot ()
122appeared in Unix V7.
123.SH "CONFORMS TO"
124XPG2. Legacy in SUSv2. Deleted in SUSv3.
125SUSv2 requires \-1 on error.
126.SH "SEE ALSO"
127.BR getttyent (3),
128.BR ttyname (3),
129.BR utmp (5)