OSDN Git Service

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