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  */
10       #include <stdlib.h>    /* on System V-like systems */
11
12       int ttyslot(void);
13

DESCRIPTION

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

RETURN VALUE

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

NOTES

63       The utmp file is found various  places  on  various  systems,  such  as
64       /etc/utmp, /var/adm/utmp, /var/run/utmp.
65
66       The  glibc2  implementation of this function reads the file _PATH_TTYS,
67       defined in <ttyent.h> as "/etc/ttys". It returns  0  on  error.   Since
68       Linux systems do not usually have "/etc/ttys", it will always return 0.
69
70       Minix also has fttyslot(fd).
71

HISTORY

73       ttyslot() appeared in Unix V7.
74

CONFORMING TO

76       SUSv1;  marked  as  LECACY  in  SUSv2;  removed in POSIX.1-2001.  SUSv2
77       requires -1 on error.
78

SEE ALSO

80       getttyent(3), ttyname(3), utmp(5)
81
82
83
84GNU                               2002-07-20                        TTYSLOT(3)
Impressum