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(): _BSD_SOURCE || (_XOPEN_SOURCE_EXTENDED &&
17       ! _XOPEN_SOURCE >= 500)
18

DESCRIPTION

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

RETURN VALUE

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

CONFORMING TO

68       SUSv1;  marked  as  LEGACY  in  SUSv2;  removed in POSIX.1-2001.  SUSv2
69       requires -1 on error.
70

NOTES

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

SEE ALSO

82       getttyent(3), ttyname(3), utmp(5)
83

COLOPHON

85       This  page  is  part of release 3.22 of the Linux man-pages project.  A
86       description of the project, and information about reporting  bugs,  can
87       be found at http://www.kernel.org/doc/man-pages/.
88
89
90
91GNU                               2007-11-26                        TTYSLOT(3)
Impressum