.\" Copyright (C) 2002 Andries Brouwer .\" .\" %%%LICENSE_START(VERBATIM) .\" 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. .\" %%%LICENSE_END .\" .\" This replaces an earlier man page written by Walter Harms .\" . .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2004 Yuichi SATO .\" all rights reserved. .\" Translated Wed Sep 8 01:25:01 JST 2004 .\" by Yuichi SATO .\" .TH TTYSLOT 3 2013\-07\-22 GNU "Linux Programmer's Manual" .SH 名前 ttyslot \- カレントユーザーの端末のスロットをファイルから探す .SH 書式 \fB#include \fP /* BSD 系のシステムと Linux の場合 */ .br \fB#include \fP /* System V 系のシステムの場合 */ .sp \fBint ttyslot(void);\fP .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp .ad l \fBttyslot\fP(): .RS 4 _BSD_SOURCE || .br _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_\ <\ 500\ &&\ _XOPEN_SOURCE_EXTENDED .RE .ad b .SH 説明 レガシーな関数 \fBttyslot\fP() は、あるファイルに書かれているカレントユーザーのエントリーのインデックスを返す。 .LP 「どのファイルなのか?」という質問があるだろう。 では、まず最初にその歴史を見てみよう。 .SS 大昔の歴史 UNIX\ V6 では \fI/etc/ttys\fP ファイルが使われていた。 \fBinit\fP(1) プログラムは、このファイルを読み込み、 各端末行で何をすべきかを探す。 各行は 3 文字から構成されている。 1 文字目は \(aq0\(aq または \(aq1\(aq であり、 \(aq0\(aq は「無視する」ことを表す。 2 文字目は端末を示す: \(aq8\(aq は "/dev/tty8" を表す。 3 文字目は \fBgetty\fP(8) への引き数であり、(接続を) 試みる回線速度の順序を表す (\(aq\-\(aq は 110 ボーで接続の試行を開始することを表す)。 よって一般的な行は "18\-" となる。 ある行でハングした場合は、\(aq1\(aq を \(aq0\(aq に変更し、 init にシグナルを送り、\(aq0\(aq を \(aq1\(aq 再度に変更し、 init に再度シグナルを送ることで解決する。 .LP UNIX\ V7 ではフォーマットが変更された: 2 文字目が \fBgetty\fP(8) の引き数となり、(接続を) 試みる回線速度の順序を表すようになり (\(aq0\(aq は 300\-1200\-150\-110 を繰り返すことを表し、 \(aq4\(aq はオンラインコンソール DECwriter を表す)、 行の残り (の文字) は端末名となった。 よって、一般的な行は "14console" となる。 .LP 後者のシステムの書式は、より精巧である。 System V 系のシステムでは、代わりに \fI/etc/inittab\fP がある。 .SS "大昔の歴史 (2)" 一方、現在ログインしている人をリストするファイル \fI/etc/utmp\fP がある。 これは \fBlogin\fP(1) によって管理されている。 このファイルは固定されたサイズであり、ファイル内の適切なインデックスは、 \fBlogin\fP(1) によって決定される。 この際に \fBttyslot\fP() が呼ばれて、 \fI/etc/ttys\fP における行番号を見つける (行番号は 1 から数える)。 .SS "ttyslot の意味" よって、関数 \fBttyslot\fP() は、ファイル \fI/etc/ttys\fP における呼び出し元のプロセスの制御端末のインデックスを返す。 これは \fI/etc/utmp\fP におけるカレントユーザーのエントリーのインデックスと (通常は) 等しい。 BSD には未だに \fI/etc/ttys\fP ファイルがあるが、System V 系のシステムにはないので、 このファイルを参照することはできない。 よって、そのようなシステムでは 「\fBttyslot\fP() はカレントユーザーのユーザーアカウントデータベースにおけるインデックスを返す」 とドキュメントに書かれている。 .SH 返り値 成功した場合、この関数はスロット番号を返す。 エラーの場合 (例えば、ファイルディスクリプター 0, 1, 2 の何れも データベースにある端末に関連づけられていない場合)、 UNIX\ V6, V7, BSD 系のシステムは 0 を返すが、 System V 系のシステムは \-1 を返す。 .SH 属性 .SS "マルチスレッディング (pthreads(7) 参照)" 関数 \fBttyslot\fP() はスレッドセーフではない関数 \fBgetttyent\fP() を呼び出す。そのため、スレッドセーフではない。 .SH 準拠 SUSv1。SUSv2 では「過去の名残 (LEGACY)」と位置付けられている。 POSIX.1\-2001 で削除された。 SUSv2 ではエラー時に \-1 を返すことが要求されている。 .SH 注意 utmp ファイルは様々なシステムで \fI/etc/utmp\fP, \fI/var/adm/utmp\fP, \fI/var/run/utmp\fP のようにいろいろな場所にある。 .LP この関数の glibc2 における実装では、ファイル \fB_PATH_TTYS\fP を読み込む。 これは \fI\fP において "/etc/ttys" と定義されている。 エラーの場合、0 を返す。 Linux システムには通常 "/etc/ttys" がないので、常に 0 を返す。 .LP .\" .SH HISTORY .\" .BR ttyslot () .\" appeared in UNIX V7. Minix には \fIfttyslot\fP(\fIfd\fP) もある。 .SH 関連項目 \fBgetttyent\fP(3), \fBttyname\fP(3), \fButmp\fP(5) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。