| .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl> |
| .\" |
| .\" Permission is granted to make and distribute verbatim copies of this |
| .\" manual provided the copyright notice and this permission notice are |
| .\" preserved on all copies. |
| .\" |
| .\" Permission is granted to copy and distribute modified versions of this |
| .\" manual under the conditions for verbatim copying, provided that the |
| .\" entire resulting derived work is distributed under the terms of a |
| .\" permission notice identical to this one. |
| .\" |
| .\" Since the Linux kernel and libraries are constantly changing, this |
| .\" manual page may be incorrect or out-of-date. The author(s) assume no |
| .\" responsibility for errors or omissions, or for damages resulting from |
| .\" the use of the information contained herein. The author(s) may not |
| .\" have taken the same level of care in the production of this manual, |
| .\" which is licensed free of charge, as they might when working |
| .\" professionally. |
| .\" |
| .\" Formatted or processed versions of this manual, if unaccompanied by |
| .\" the source, must acknowledge the copyright and authors of this work. |
| .\" |
| .\" This replaces an earlier man page written by Walter Harms |
| .\" <walter.harms@informatik.uni-oldenburg.de>. |
| .\" |
| .TH TTYSLOT 3 2002-07-20 "GNU" "Linux Programmer's Manual" |
| .SH NAME |
| ttyslot \- find the slot of the current user's terminal in some file |
| .SH SYNOPSIS |
| .sp |
| .BR "#include <unistd.h>" " /* on BSD-like systems */" |
| .br |
| .BR "#include <stdlib.h>" " /* on System V-like systems */" |
| .sp |
| .B "int ttyslot(void);" |
| .SH DESCRIPTION |
| The legacy function |
| .BR ttyslot () |
| returns the index of the current user's entry in some file. |
| .LP |
| Now "What file?" you ask. Well, let's first look at some history. |
| .SS "Ancient History" |
| There used to be a file |
| .I /etc/ttys |
| in Unix V6, that was read by the |
| .BR init (8) |
| program to find out what to do with each terminal line. |
| Each line consisted of three characters. |
| The first character was either '0' or '1', where '0' meant "ignore". |
| The second character denoted the terminal: '8' stood for "/dev/tty8". |
| The third character was an argument to |
| .BR getty (8) |
| indicating the sequence of line speeds to try ('\-' was: start trying |
| 110 baud). Thus a typical line was "18\-". |
| A hang on some line was solved by changing the '1' to a '0', |
| signalling init, changing back again, and signalling init again. |
| .LP |
| In Unix V7 the format was changed: here the second character |
| was the argument to |
| .BR getty (8) |
| indicating the sequence of line speeds to try ('0' was: cycle through |
| 300-1200-150-110 baud; '4' was for the on-line console DECwriter) |
| while the rest of the line contained the name of the tty. |
| Thus a typical line was "14console". |
| .LP |
| Later systems have more elaborate syntax. |
| System V-like systems have |
| .I /etc/inittab |
| instead. |
| .SS "Ancient History (2)" |
| On the other hand, there is the file |
| .I /etc/utmp |
| listing the people currently logged in. It is maintained by |
| .BR login (8). |
| It has a fixed size, and the appropriate index in the file was |
| determined by |
| .BR login (8) |
| using the |
| .BR ttyslot () |
| call to find the number of the line in |
| .IR /etc/ttys |
| (counting from 1). |
| .SS "The semantics of ttyslot" |
| Thus, the function |
| .BR ttyslot () |
| returns the index of the controlling terminal of the current process |
| in the file |
| .IR /etc/ttys , |
| and that is (usually) the same as the index of the entry for the |
| current user in the file |
| .IR /etc/utmp . |
| BSD still has the |
| .I /etc/ttys |
| file, but System V-like systems do not, and hence cannot refer to it. |
| Thus, on such systems the documentation says that |
| .BR ttyslot () |
| returns the current user's index in the user accounting data base. |
| .SH "RETURN VALUE" |
| If successful, this function returns the slot number. |
| On error (e.g., if none of the file descriptors 0, 1 or 2 is |
| associated with a terminal that occurs in this data base) |
| it returns 0 on Unix V6 and V7 and BSD-like systems, |
| but \-1 on System V-like systems. |
| .SH NOTES |
| The utmp file is found various places on various systems, such as |
| .IR /etc/utmp , |
| .IR /var/adm/utmp , |
| .IR /var/run/utmp . |
| .LP |
| The glibc2 implementation of this function reads the file |
| .BR _PATH_TTYS , |
| defined in |
| .I <ttyent.h> |
| as "/etc/ttys". It returns 0 on error. |
| Since Linux systems do not usually have "/etc/ttys", it will |
| always return 0. |
| .LP |
| Minix also has |
| .IR fttyslot ( fd ). |
| .SH HISTORY |
| .BR ttyslot () |
| appeared in Unix V7. |
| .SH "CONFORMS TO" |
| XPG2. Legacy in SUSv2. Deleted in SUSv3. |
| SUSv2 requires \-1 on error. |
| .SH "SEE ALSO" |
| .BR getttyent (3), |
| .BR ttyname (3), |
| .BR utmp (5) |