1TTYSLOT(3)                 Linux Programmer's Manual                TTYSLOT(3)
2
3
4

NAME

6       ttyslot - find the slot of the current user's terminal in some file
7

SYNOPSIS

9       #include <unistd.h>    /* on BSD-like systems, and Linux */
10       #include <stdlib.h>    /* on System V-like systems */
11
12       int ttyslot(void);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       ttyslot():
17           _BSD_SOURCE ||
18           _XOPEN_SOURCE && _XOPEN_SOURCE_ < 500 && _XOPEN_SOURCE_EXTENDED
19

DESCRIPTION

21       The  legacy  function ttyslot() returns the index of the current user's
22       entry in some file.
23
24       Now "What file?" you ask.  Well, let's first look at some history.
25
26   Ancient history
27       There used to be a file /etc/ttys in UNIX V6,  that  was  read  by  the
28       init(8)  program  to find out what to do with each terminal line.  Each
29       line consisted of three characters.  The first character was either '0'
30       or  '1',  where  '0'  meant "ignore".  The second character denoted the
31       terminal: '8' stood for "/dev/tty8".  The third character was an  argu‐
32       ment  to  getty(8)  indicating  the sequence of line speeds to try ('-'
33       was: start trying 110 baud).  Thus a typical line was "18-".  A hang on
34       some  line  was  solved  by  changing the '1' to a '0', signaling init,
35       changing back again, and signaling init again.
36
37       In UNIX V7 the format was changed: here the second  character  was  the
38       argument to getty(8) indicating the sequence of line speeds to try ('0'
39       was: cycle through 300-1200-150-110 baud; '4' was for the on-line  con‐
40       sole  DECwriter)  while  the rest of the line contained the name of the
41       tty.  Thus a typical line was "14console".
42
43       Later systems have more elaborate syntax.  System V-like  systems  have
44       /etc/inittab instead.
45
46   Ancient history (2)
47       On  the other hand, there is the file /etc/utmp listing the people cur‐
48       rently logged in.  It is maintained by login(1).  It has a fixed  size,
49       and  the appropriate index in the file was determined by login(1) using
50       the ttyslot() call to find the number of the line in /etc/ttys  (count‐
51       ing from 1).
52
53   The semantics of ttyslot
54       Thus,  the function ttyslot() returns the index of the controlling ter‐
55       minal of the calling process in the file /etc/ttys, and that  is  (usu‐
56       ally)  the  same  as the index of the entry for the current user in the
57       file /etc/utmp.  BSD still has the /etc/ttys file,  but  System  V-like
58       systems  do  not,  and hence cannot refer to it.  Thus, on such systems
59       the documentation says that ttyslot() returns the current user's  index
60       in the user accounting data base.
61

RETURN VALUE

63       If  successful, this function returns the slot number.  On error (e.g.,
64       if none of the file descriptors 0, 1 or 2 is associated with a terminal
65       that  occurs in this data base) it returns 0 on UNIX V6 and V7 and BSD-
66       like systems, but -1 on System V-like systems.
67

ATTRIBUTES

69   Multithreading (see pthreads(7))
70       The ttyslot() function calls thread-unsafe function getttyent(), so  it
71       is not thread-safe.
72

CONFORMING TO

74       SUSv1;  marked  as  LEGACY  in  SUSv2;  removed in POSIX.1-2001.  SUSv2
75       requires -1 on error.
76

NOTES

78       The utmp file is found various  places  on  various  systems,  such  as
79       /etc/utmp, /var/adm/utmp, /var/run/utmp.
80
81       The  glibc2  implementation of this function reads the file _PATH_TTYS,
82       defined in <ttyent.h> as "/etc/ttys".  It returns 0  on  error.   Since
83       Linux systems do not usually have "/etc/ttys", it will always return 0.
84
85       Minix also has fttyslot(fd).
86

SEE ALSO

88       getttyent(3), ttyname(3), utmp(5)
89

COLOPHON

91       This  page  is  part of release 3.53 of the Linux man-pages project.  A
92       description of the project, and information about reporting  bugs,  can
93       be found at http://www.kernel.org/doc/man-pages/.
94
95
96
97GNU                               2013-07-22                        TTYSLOT(3)
Impressum