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