ttyslotのヘルプ・マニュアル
日本語 英語
ttyslot --help
man ttyslot
TTYSLOT(3) Linux Programmer’s Manual TTYSLOT(3)
名前
ttyslot - カレントユーザの端末のスロットをファイルから探す
書式
#include /* BSD 系のシステムと Linux の場合 */
#include /* System V 系のシステムの場合 */
int ttyslot(void);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
ttyslot(): _BSD_SOURCE || (_XOPEN_SOURCE_EXTENDED &&
! _XOPEN_SOURCE >= 500)
説明
レガシーな関数 ttyslot() は、あるファイルに書かれているカレントユーザの
エントリのインデックスを返す。
「 どのファイルなのか?」という質問があるだろう。では、まず最初にその歴
史を見てみよう。
大昔の歴史
Unix V6 では /etc/ttys ファイルが使われていた。 init(8) プログラムは 、
このファイルを読み込み、各端末行で何をすべきかを探す。各行は 3 文字から
構成されている。 1 文字目は '0' または '1' であり、 '0' は「無視する 」
ことを表す。 2 文字目は端末を示す: '8' は "/dev/tty8" を表す。 3 文字目
は getty(8) への引き数であり、(接続を) 試みる回線速度の順序を表す ('-'
は 110 ボーで接続の試行を開始することを表す)。よって一般的な行は "18-"
となる。ある行でハングした場合は、'1' を '0' に変更し、 init にシグナル
を送り、'0' を '1' 再度に変更し、 init に再度シグナルを送ることで解決す
る。
Unix V7 ではフォーマットが変更された: 2 文字目が getty(8) の引き数と な
り 、( 接 続 を) 試 み る 回 線 速 度 の 順序を表すようになり ('0' は
300-1200-150-110 を繰り返すことを表し、 '4' はオンライン コ ン ソ ー ル
DECwriter を表す)、行の残り (の文字) は端末名となった。よって、一般的な
行は "14console" となる。
後者のシステムの書式は、より精巧である。 System V 系のシステムでは、 代
わりに /etc/inittab がある。
大昔の歴史 (2)
一方、現在ログインしている人をリストするファイル /etc/utmp がある。これ
は login(1) によって管理されている。このファイルは固定されたサイズで あ
り 、ファイル内の適切なインデックスは、 login(1) によって決定される。こ
の際に ttyslot() が呼ばれて、 /etc/ttys における行番号を見つける (行 番
号は 1 から数える)。
ttyslot の意味
よ って、関数 ttyslot() は、ファイル /etc/ttys における呼び出し元のプロ
セスの制御端末のインデックスを返す。これは /etc/utmp におけるカレントユ
ー ザ の エ ン ト リ の インデックスと (通常は) 等しい。 BSD には未だに
/etc/ttys ファイルがあるが、System V 系のシステムにはないので、このファ
イ ル を 参照することはできない。よって、そのようなシステムでは 「ttys-
lot() はカレントユーザのユーザアカウントデータベースにおけるインデッ ク
スを返す」とドキュメントに書かれている。
返り値
成 功した場合、この関数はスロット番号を返す。エラーの場合 (例えば、ファ
イルディスクリプタ 0, 1, 2 の何れもデータベースにある端末に関連づけられ
て い ない場合)、 Unix V6, V7, BSD 系のシステムは 0 を返すが、 System V
系のシステムは -1 を返す。
準拠
SUSv1。SUSv2 では「過去の名残 (LEGACY)」と位 置 付 け ら れ て い る 。
POSIX.1-2001 で削除された。 SUSv2 ではエラー時に -1 を返すことが要求さ
れている。
注意
utmp ファイルは様々なシステムで /etc/utmp, /var/adm/utmp, /var/run/utmp
のようにいろいろな場所にある。
こ の関数の glibc2 における実装では、ファイル _PATH_TTYS を読み込む。こ
れは において "/etc/ttys" と定義されている。エラーの場合 、0
を返す。 Linux システムには通常 "/etc/ttys" がないので、常に 0 を返す。
Minix には fttyslot(fd) もある。
関連項目
getttyent(3), ttyname(3), utmp(5)
GNU 2007-11-26 TTYSLOT(3)
TTYSLOT(3) Linux Programmer’s Manual TTYSLOT(3)
NAME
ttyslot - find the slot of the current user’s terminal in some file
SYNOPSIS
#include /* on BSD-like systems, and Linux */
#include /* on System V-like systems */
int ttyslot(void);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
ttyslot(): _BSD_SOURCE || (_XOPEN_SOURCE_EXTENDED &&
! _XOPEN_SOURCE >= 500)
DESCRIPTION
The legacy function ttyslot() returns the index of the current user’s
entry in some file.
Now "What file?" you ask. Well, let’s first look at some history.
Ancient History
There used to be a file /etc/ttys in Unix V6, that was read by the
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 argu-
ment to 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', signaling init,
changing back again, and signaling init again.
In Unix V7 the format was changed: here the second character was the
argument to 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 con-
sole DECwriter) while the rest of the line contained the name of the
tty. Thus a typical line was "14console".
Later systems have more elaborate syntax. System V-like systems have
/etc/inittab instead.
Ancient History (2)
On the other hand, there is the file /etc/utmp listing the people cur-
rently logged in. It is maintained by login(1). It has a fixed size,
and the appropriate index in the file was determined by login(1) using
the ttyslot() call to find the number of the line in /etc/ttys (count-
ing from 1).
The semantics of ttyslot
Thus, the function ttyslot() returns the index of the controlling ter-
minal of the calling process in the file /etc/ttys, and that is (usu-
ally) the same as the index of the entry for the current user in the
file /etc/utmp. BSD still has the /etc/ttys file, but System V-like
systems do not, and hence cannot refer to it. Thus, on such systems
the documentation says that ttyslot() returns the current user’s index
in the user accounting data base.
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.
CONFORMING TO
SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001. SUSv2
requires -1 on error.
NOTES
The utmp file is found various places on various systems, such as
/etc/utmp, /var/adm/utmp, /var/run/utmp.
The glibc2 implementation of this function reads the file _PATH_TTYS,
defined in as "/etc/ttys". It returns 0 on error. Since
Linux systems do not usually have "/etc/ttys", it will always return 0.
Minix also has fttyslot(fd).
SEE ALSO
getttyent(3), ttyname(3), utmp(5)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2007-11-26 TTYSLOT(3)