273 lines
7.1 KiB
HTML
273 lines
7.1 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of TTYSLOT</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>TTYSLOT</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
ttyslot - find the slot of the current user's terminal in some file
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B> /See NOTES */
|
|
|
|
<P>
|
|
|
|
<B>int ttyslot(void);</B>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
|
|
<B>ttyslot</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
Since glibc 2.24:
|
|
<BR> _DEFAULT_SOURCE
|
|
<BR>
|
|
|
|
From glibc 2.20 to 2.23:
|
|
<BR> _DEFAULT_SOURCE ||
|
|
<BR> _XOPEN_SOURCE && _XOPEN_SOURCE < 500
|
|
<BR>
|
|
|
|
Glibc 2.19 and earlier:
|
|
<BR> _BSD_SOURCE ||
|
|
<BR> _XOPEN_SOURCE && _XOPEN_SOURCE < 500
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The legacy function
|
|
<B>ttyslot</B>()
|
|
|
|
returns the index of the current user's entry in some file.
|
|
<P>
|
|
|
|
Now "What file?" you ask.
|
|
Well, let's first look at some history.
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Ancient history</H3>
|
|
|
|
There used to be a file
|
|
<I>/etc/ttys</I>
|
|
|
|
in UNIX V6, that was read by the
|
|
<B><A HREF="/cgi-bin/man/man2html?1+init">init</A></B>(1)
|
|
|
|
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
|
|
<B><A HREF="/cgi-bin/man/man2html?8+getty">getty</A></B>(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',
|
|
signaling init, changing back again, and signaling init again.
|
|
<P>
|
|
|
|
In UNIX V7 the format was changed: here the second character
|
|
was the argument to
|
|
<B><A HREF="/cgi-bin/man/man2html?8+getty">getty</A></B>(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".
|
|
<P>
|
|
|
|
Later systems have more elaborate syntax.
|
|
System V-like systems have
|
|
<I>/etc/inittab</I>
|
|
|
|
instead.
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Ancient history (2)</H3>
|
|
|
|
On the other hand, there is the file
|
|
<I>/etc/utmp</I>
|
|
|
|
listing the people currently logged in.
|
|
It is maintained by
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1).
|
|
|
|
It has a fixed size, and the appropriate index in the file was
|
|
determined by
|
|
<B><A HREF="/cgi-bin/man/man2html?1+login">login</A></B>(1)
|
|
|
|
using the
|
|
<B>ttyslot</B>()
|
|
|
|
call to find the number of the line in
|
|
<I>/etc/ttys</I>
|
|
|
|
(counting from 1).
|
|
<A NAME="lbAG"> </A>
|
|
<H3>The semantics of ttyslot</H3>
|
|
|
|
Thus, the function
|
|
<B>ttyslot</B>()
|
|
|
|
returns the index of the controlling terminal of the calling process
|
|
in the file
|
|
<I>/etc/ttys</I>,
|
|
|
|
and that is (usually) the same as the index of the entry for the
|
|
current user in the file
|
|
<I>/etc/utmp</I>.
|
|
|
|
BSD still has the
|
|
<I>/etc/ttys</I>
|
|
|
|
file, but System V-like systems do not, and hence cannot refer to it.
|
|
Thus, on such systems the documentation says that
|
|
<B>ttyslot</B>()
|
|
|
|
returns the current user's index in the user accounting data base.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
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.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>ttyslot</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
|
|
SUSv2 requires -1 on error.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The utmp file is found in various places on various systems, such as
|
|
<I>/etc/utmp</I>,
|
|
|
|
<I>/var/adm/utmp</I>,
|
|
|
|
<I>/var/run/utmp</I>.
|
|
|
|
<P>
|
|
|
|
The glibc2 implementation of this function reads the file
|
|
<B>_PATH_TTYS</B>,
|
|
|
|
defined in
|
|
<I><<A HREF="file:///usr/include/ttyent.h">ttyent.h</A>></I>
|
|
|
|
as "/etc/ttys".
|
|
It returns 0 on error.
|
|
Since Linux systems do not usually have "/etc/ttys", it will
|
|
always return 0.
|
|
<P>
|
|
|
|
On BSD-like systems and Linux, the declaration of
|
|
<B>ttyslot</B>()
|
|
|
|
is provided by
|
|
<I><<A HREF="file:///usr/include/unistd.h">unistd.h</A>></I>.
|
|
|
|
On System V-like systems, the declaration is provided by
|
|
<I><<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>></I>.
|
|
|
|
Since glibc 2.24,
|
|
<I><<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>></I>
|
|
|
|
also provides the declaration with the following
|
|
feature test macro definitions:
|
|
<P>
|
|
|
|
|
|
|
|
(_XOPEN_SOURCE >= 500 ||
|
|
<BR> (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
|
|
<BR> && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
|
|
|
|
|
|
<P>
|
|
|
|
Minix also has
|
|
<I>fttyslot</I>(<I>fd</I>).
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getttyent">getttyent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ttyname">ttyname</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+utmp">utmp</A></B>(5)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="5"><A HREF="#lbAE">Ancient history</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">Ancient history (2)</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">The semantics of ttyslot</A><DD>
|
|
</DL>
|
|
<DT id="8"><A HREF="#lbAH">RETURN VALUE</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">ATTRIBUTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAJ">CONFORMING TO</A><DD>
|
|
<DT id="11"><A HREF="#lbAK">NOTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="13"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:58 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|