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