OSDN Git Service

LDP: Update draft based on the previous commit
authorAkihiro Motoki <amotoki@gmail.com>
Sat, 27 Mar 2021 10:24:46 +0000 (19:24 +0900)
committerAkihiro Motoki <amotoki@gmail.com>
Sat, 27 Mar 2021 10:24:46 +0000 (19:24 +0900)
13 files changed:
manual/LDP_man-pages/draft/man2/epoll_create.2
manual/LDP_man-pages/draft/man2/epoll_wait.2 [new file with mode: 0644]
manual/LDP_man-pages/draft/man2/getdents.2 [new file with mode: 0644]
manual/LDP_man-pages/draft/man2/poll.2 [new file with mode: 0644]
manual/LDP_man-pages/draft/man2/readdir.2
manual/LDP_man-pages/draft/man3/abort.3
manual/LDP_man-pages/draft/man3/assert.3
manual/LDP_man-pages/draft/man3/dirfd.3
manual/LDP_man-pages/draft/man3/err.3
manual/LDP_man-pages/draft/man3/errno.3 [new file with mode: 0644]
manual/LDP_man-pages/draft/man3/getdirentries.3
manual/LDP_man-pages/draft/man3/scandir.3
manual/LDP_man-pages/draft/man7/epoll.7 [new file with mode: 0644]

index a436d18..b097130 100644 (file)
@@ -48,8 +48,9 @@ epoll_create, epoll_create1 \- epoll ファイルディスクリプターをオ
 \fBint epoll_create1(int \fP\fIflags\fP\fB);\fP
 .fi
 .SH 説明
-\fBepoll_create\fP()  creates a new \fBepoll\fP(7)  instance.  Since Linux 2.6.8,
-the \fIsize\fP argument is ignored, but must be greater than zero; see NOTES.
+\fBepoll_create\fP() は新規の \fBepoll\fP(7) インスタンスを作成する。
+Linux 2.6.8 以降では、\fIsize\fP 引き数は無視されるが、 0 より大きな値で
+なければならない。「注意」を参照。
 .PP
 \fBepoll_create\fP()  は、新しい epoll インスタンスを参照するファイルディスクリプターを返す。
 このファイルディスクリプターは、その後の \fBepoll\fP インターフェースの呼び出しに使われる。 もう必要でなくなった場合は、
@@ -65,9 +66,8 @@ epoll インスタンスを参照する全てのファイルディスクリプ
 新しいファイルディスクリプターに対して close\-on\-exec (\fBFD_CLOEXEC\fP)  フラグをセットする。
 このフラグが役に立つ理由については、 \fBopen\fP(2)  の \fBO_CLOEXEC\fP フラグの説明を参照のこと。
 .SH 返り値
-On success, these system calls return a file descriptor (a nonnegative
-integer).  On error, \-1 is returned, and \fIerrno\fP is set to indicate the
-error.
+成功すると、これらのシステムコールはファイルディスクリプター (非負の整数) を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP
+にエラーを示す値を設定する。
 .SH エラー
 .TP 
 \fBEINVAL\fP
diff --git a/manual/LDP_man-pages/draft/man2/epoll_wait.2 b/manual/LDP_man-pages/draft/man2/epoll_wait.2
new file mode 100644 (file)
index 0000000..9d05cc5
--- /dev/null
@@ -0,0 +1,189 @@
+.\"  Copyright (C) 2003  Davide Libenzi
+.\"  Davide Libenzi <davidel@xmailserver.org>
+.\" and Copyright 2007, 2012, 2014, 2018 Michael Kerrisk <tk.manpages@gmail.com>
+.\"
+.\" %%%LICENSE_START(GPLv2+_SW_3_PARA)
+.\"  This program is free software; you can redistribute it and/or modify
+.\"  it under the terms of the GNU General Public License as published by
+.\"  the Free Software Foundation; either version 2 of the License, or
+.\"  (at your option) any later version.
+.\"
+.\"  This program is distributed in the hope that it will be useful,
+.\"  but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\"  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+.\"  GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public
+.\" License along with this manual; if not, see
+.\" <http://www.gnu.org/licenses/>.
+.\" %%%LICENSE_END
+.\"
+.\" 2007-04-30: mtk, Added description of epoll_pwait()
+.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
+.\" Japanese Version Copyright (c) 2004-2005 Yuichi SATO
+.\"         all rights reserved.
+.\" Translated Wed Jun 16 03:05:40 JST 2004
+.\"         by Yuichi SATO <ysato444@yahoo.co.jp>
+.\" Updated & Modified Tue Apr 19 07:05:42 JST 2005 by Yuichi SATO
+.\" Updated 2007-06-02, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.51
+.\" Updated 2009-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.18
+.\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
+.\"
+.TH EPOLL_WAIT 2 2020\-04\-11 Linux "Linux Programmer's Manual"
+.SH 名前
+epoll_wait, epoll_pwait \- epoll ファイルディスクリプターの I/O イベントを待つ
+.SH 書式
+.nf
+\fB#include <sys/epoll.h>\fP
+.PP
+\fBint epoll_wait(int \fP\fIepfd\fP\fB, struct epoll_event *\fP\fIevents\fP\fB,\fP
+\fB               int \fP\fImaxevents\fP\fB, int \fP\fItimeout\fP\fB);\fP
+\fBint epoll_pwait(int \fP\fIepfd\fP\fB, struct epoll_event *\fP\fIevents\fP\fB,\fP
+\fB               int \fP\fImaxevents\fP\fB, int \fP\fItimeout\fP\fB,\fP
+\fB               const sigset_t *\fP\fIsigmask\fP\fB);\fP
+.fi
+.SH 説明
+The \fBepoll_wait\fP()  system call waits for events on the \fBepoll\fP(7)
+instance referred to by the file descriptor \fIepfd\fP.  The buffer pointed to
+by \fIevents\fP is used to return information from the ready list about file
+descriptors in the interest list that have some events available.  Up to
+\fImaxevents\fP are returned by \fBepoll_wait\fP().  The \fImaxevents\fP argument
+must be greater than zero.
+.PP
+The \fItimeout\fP argument specifies the number of milliseconds that
+\fBepoll_wait\fP()  will block.  Time is measured against the
+\fBCLOCK_MONOTONIC\fP clock.
+.PP
+A call to \fBepoll_wait\fP()  will block until either:
+.IP \(bu 2
+ファイルディスクリプターがイベントを配送した
+.IP \(bu
+呼び出しがシグナルハンドラーにより割り込まれた
+.IP \(bu
+タイムアウトが満了する
+.PP
+\fItimeout\fP 時間はシステムクロックの粒度に切り上げられ、カーネルのスケジューリング遅延により少しだけ長くなる可能性がある点に注意すること。
+\fItimeout\fP を \-1 に指定すると、 \fBepoll_wait\fP() は無限に停止する。 \fItimeout\fP を 0 に指定すると、
+\fBepoll_wait\fP() は利用可能なイベントがなくても、すぐに返る。
+.PP
+\fIstruct epoll_event\fP は以下のように定義される。
+.PP
+.in +4n
+.EX
+typedef union epoll_data {
+    void    *ptr;
+    int      fd;
+    uint32_t u32;
+    uint64_t u64;
+} epoll_data_t;
+
+struct epoll_event {
+    uint32_t     events;    /* epoll イベント */
+    epoll_data_t data;      /* ユーザーデータ変数 */
+};
+.EE
+.in
+.PP
+The \fIdata\fP field of each returned \fIepoll_event\fP structure contains the
+same data as was specified in the most recent call to \fBepoll_ctl\fP(2)
+(\fBEPOLL_CTL_ADD\fP, \fBEPOLL_CTL_MOD\fP)  for the corresponding open file
+descriptor.
+.PP
+.\"
+The \fIevents\fP field is a bit mask that indicates the events that have
+occurred for the corresponding open file description.  See \fBepoll_ctl\fP(2)
+for a list of the bits that may appear in this mask.
+.SS epoll_pwait()
+\fBepoll_wait\fP()  と \fBepoll_pwait\fP()  の関係は、 \fBselect\fP(2)  と \fBpselect\fP(2)
+の関係と同様である。 \fBpselect\fP(2)  同様、 \fBepoll_pwait\fP()
+を使うと、アプリケーションは、ファイルディスクリプターが準備できた状態になるか、 シグナルが捕捉されるまで、安全に待つことができる。
+.PP
+以下の \fBepoll_pwait\fP()  の呼び出しは、
+.PP
+.in +4n
+.EX
+ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
+.EE
+.in
+.PP
+次の呼び出しを \fIatomic\fP に実行するのと等価である。
+.PP
+.in +4n
+.EX
+sigset_t origmask;
+
+pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
+ready = epoll_wait(epfd, &events, maxevents, timeout);
+pthread_sigmask(SIG_SETMASK, &origmask, NULL);
+.EE
+.in
+.PP
+\fIsigmask\fP 引き数には NULL を指定してもよい。 その場合には、 \fBepoll_pwait\fP()  は \fBepoll_wait\fP()
+と等価となる。
+.SH 返り値
+成功した場合、 \fBepoll_wait\fP()  は要求された I/O に対して準備ができているファイルディスクリプターの数を返す。 また要求された
+\fItimeout\fP ミリ秒の間にファイルディスクリプターが準備できない場合は、0 を返す。 エラーが起こった場合、 \fBepoll_wait\fP()
+は \-1 を返し、 \fIerrno\fP を適切に設定する。
+.SH エラー
+.TP 
+\fBEBADF\fP
+\fIepfd\fP が有効なファイルディスクリプターでない。
+.TP 
+\fBEFAULT\fP
+\fIevents\fP で指されるメモリー領域に書き込み権限でアクセスできない。
+.TP 
+\fBEINTR\fP
+(1) 要求されたどのイベントも発生せず、かつ (2) \fItimeout\fP
+の期限が切れる前に、システムコールがシグナルハンドラーによって割り込まれた。 \fBsignal\fP(7) 参照。
+.TP 
+\fBEINVAL\fP
+\fIepfd\fP が \fBepoll\fP ファイルディスクリプターでない。 または \fImaxevents\fP が 0 以下である。
+.SH バージョン
+.\" To be precise: kernel 2.5.44.
+.\" The interface should be finalized by Linux kernel 2.5.66.
+\fBepoll_wait\fP() はカーネル 2.6 で追加された。
+ライブラリによるサポートは glibc バージョン 2.3.2 以降で提供されている。
+.PP
+\fBepoll_pwait\fP() はカーネル 2.6.19 で Linux に追加された。
+ライブラリによるサポートは glibc バージョン 2.6 以降で提供されている。
+.SH 準拠
+\fBepoll_wait\fP() は Linux 独自である。
+.SH 注意
+あるスレッドが \fBepoll_wait\fP() を呼び出して停止されている間に、別のスレッドが wait 中の \fBepoll\fP
+インストールにファイルディスクリプターを追加することがある。新しいファイルディスクリプターでイベントが発生すると、 \fBepoll_wait\fP()
+の呼び出しによる停止が解除されることになる。
+.PP
+If more than \fImaxevents\fP file descriptors are ready when \fBepoll_wait\fP()
+is called, then successive \fBepoll_wait\fP()  calls will round robin through
+the set of ready file descriptors.  This behavior helps avoid starvation
+scenarios, where a process fails to notice that additional file descriptors
+are ready because it focuses on a set of file descriptors that are already
+known to be ready.
+.PP
+Note that it is possible to call \fBepoll_wait\fP()  on an \fBepoll\fP instance
+whose interest list is currently empty (or whose interest list becomes empty
+because file descriptors are closed or removed from the interest in another
+thread).  The call will block until some file descriptor is later added to
+the interest list (in another thread) and that file descriptor becomes
+ready.
+.SH バグ
+バージョン 2.6.37 より前のカーネルでは、おおよそ \fILONG_MAX / HZ\fP ミリ秒より大きい \fItimeout\fP 値は \-1
+(つまり無限大) として扱われる。したがって、例えば、\fIsizeof(long)\fP が 4 で、カーネルの \fIHZ\fP の値が 1000
+のシステムでは、 35.79 分よりも大きなタイムアウトは無限大として扱われるということである。
+.SS "C ライブラリとカーネルの違い"
+素の \fBepoll_pwait\fP() システムコールは 6 番目の引き数 \fIsize_t sigsetsize\fP を取る。 この引き数は
+\fIsigmask\fP 引き数のバイト単位のサイズを指定する。 glibc の \fBepoll_pwait\fP() ラッパー関数は、この引き数に固定値
+(\fIsizeof(sigset_t)\fP と同じ) を指定する。
+.SH 関連項目
+\fBepoll_create\fP(2), \fBepoll_ctl\fP(2), \fBepoll\fP(7)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
+\%https://www.kernel.org/doc/man\-pages/ に書かれている。
diff --git a/manual/LDP_man-pages/draft/man2/getdents.2 b/manual/LDP_man-pages/draft/man2/getdents.2
new file mode 100644 (file)
index 0000000..113eded
--- /dev/null
@@ -0,0 +1,274 @@
+.\" Copyright (C) 1995 Andries Brouwer (aeb@cwi.nl)
+.\" and Copyright 2008, 2015 Michael Kerrisk <mtk.manpages@gmail.com>
+.\"
+.\" %%%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
+.\"
+.\" Written 11 June 1995 by Andries Brouwer <aeb@cwi.nl>
+.\" Modified 22 July 1995 by Michael Chastain <mec@duracef.shout.net>:
+.\"   Derived from 'readdir.2'.
+.\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
+.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
+.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
+.\"         all rights reserved.
+.\" Translated Sat Feb 22 20:15:56 JST 1997
+.\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
+.\" Updated Sun Oct 12 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
+.\" Updated Wed Jul 30 JST 2008 by Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2009-02-12 by Kentaro Shirakata <argrath@ub32.org>
+.\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
+.\"
+.TH GETDENTS 2 2020\-11\-01 Linux "Linux Programmer's Manual"
+.SH 名前
+getdents, getdents64 \- ディレクトリエントリーを取得する
+.SH 書式
+.nf
+\fBlong getdents(unsigned int \fP\fIfd\fP\fB, struct linux_dirent *\fP\fIdirp\fP\fB,\fP
+\fB             unsigned int \fP\fIcount\fP\fB);\fP
+.PP
+\fB#define _GNU_SOURCE\fP        /* feature_test_macros(7) 参照 */
+\fB#include <dirent.h>\fP
+.PP
+\fBssize_t getdents64(int \fP\fIfd\fP\fB, void *\fP\fIdirp\fP\fB, size_t \fP\fIcount\fP\fB);\fP
+.fi
+.PP
+\fI注\fP: \fBgetdents\fP() の glibc のラッパー関数は存在しない。「注意」の節を参照。
+.SH 説明
+これらはあなたの関心を引くようなインターフェースではない。 POSIX 準拠の C ライブラリインターフェースについては \fBreaddir\fP(3)
+を見ること。 このページは、カーネルシステムコールの生のインターフェースについて 記載したものである。
+.SS getdents()
+\fBgetdents\fP()  システムコールは、オープン済みのファイルディスクリプター \fIfd\fP で参照されるディレクトリから
+\fIlinux_dirent\fP 構造体をいくつか読み出し、 \fIdirp\fP が指しているバッファーに格納する。 \fIcount\fP
+引き数はそのバッファーのサイズを示す。
+.PP
+\fIlinux_dirent\fP 構造体は以下のように宣言されている:
+.PP
+.in +4n
+.EX
+struct linux_dirent {
+    unsigned long  d_ino;     /* Inode number */
+    unsigned long  d_off;     /* Offset to next \fIlinux_dirent\fP */
+    unsigned short d_reclen;  /* Length of this \fIlinux_dirent\fP */
+    char           d_name[];  /* Filename (null\-terminated) */
+                      /* length is actually (d_reclen \- 2 \-
+                         offsetof(struct linux_dirent, d_name)) */
+    /*
+    char           pad;       // Zero padding byte
+    char           d_type;    // File type (only since Linux
+                              // 2.6.4); offset is (d_reclen \- 1)
+    */
+}
+.EE
+.in
+.PP
+\fId_ino\fP は inode 番号である。 \fId_off\fP はディレクトリの先頭から次の \fIlinux_dirent\fP の先頭までの距離である。
+\fId_reclen\fP はこの \fIlinux_dirent\fP 全体のサイズである。 \fId_name\fP はヌル文字で終わるファイル名である。
+.PP
+\fId_type\fP は、構造体の最後のバイトであり、ファイルタイプを示す。 \fId_type\fP は以下の値の一つを取る
+(\fI<dirent.h>\fP で定義されている)。
+.TP  12
+\fBDT_BLK\fP
+ブロックデバイスである。
+.TP 
+\fBDT_CHR\fP
+キャラクターデバイスである。
+.TP 
+\fBDT_DIR\fP
+ディレクトリである。
+.TP 
+\fBDT_FIFO\fP
+名前付きパイプ (FIFO) である。
+.TP 
+\fBDT_LNK\fP
+シンボリックリンクである。
+.TP 
+\fBDT_REG\fP
+通常のファイルである。
+.TP 
+\fBDT_SOCK\fP
+UNIX ドメインソケットである。
+.TP 
+\fBDT_UNKNOWN\fP
+ファイルタイプが不明である。
+.PP
+\fId_type\fP フィールドは Linux 2.6.4 から実装されている。 これは \fIlinux_dirent\fP
+構造体のうち、以前はゼロで埋められていた空間に配置されている。 従って、2.6.3 以前のカーネルでは、このフィールドにアクセスしようとすると 常に値
+0 (\fBDT_UNKNOWN\fP)  が返される。
+.PP
+.\" kernel 2.6.27
+.\" The same sentence is in readdir.2
+現在のところ、 \fId_type\fP でファイルタイプを返す機能が完全にサポートされているのは、 いくつかのファイルシステムにおいてのみである
+(Btrfs, ext2, ext3, ext4 はサポートしている)。 どのアプリケーションも、 \fBDT_UNKNOWN\fP
+が返された際に適切に処理できなければならない。
+.SS getdents64()
+The original Linux \fBgetdents\fP()  system call did not handle large
+filesystems and large file offsets.  Consequently, Linux 2.4 added
+\fBgetdents64\fP(), with wider types for the \fId_ino\fP and \fId_off\fP fields.  In
+addition, \fBgetdents64\fP()  supports an explicit \fId_type\fP field.
+.PP
+The \fBgetdents64\fP()  system call is like \fBgetdents\fP(), except that its
+second argument is a pointer to a buffer containing structures of the
+following type:
+.PP
+.in +4n
+.EX
+struct linux_dirent64 {
+    ino64_t        d_ino;    /* 64\-bit inode number */
+    off64_t        d_off;    /* 64\-bit offset to next structure */
+    unsigned short d_reclen; /* Size of this dirent */
+    unsigned char  d_type;   /* File type */
+    char           d_name[]; /* Filename (null\-terminated) */
+};
+.EE
+.in
+.SH 返り値
+成功した場合は、読み込んだバイト数が返される。 ディレクトリの終わりならば 0 が返される。 エラーの場合は \-1 を返され、 \fIerrno\fP
+に適切な値が設定される。
+.SH エラー
+.TP 
+\fBEBADF\fP
+ファイルディスクリプター \fIfd\fP が不正である。
+.TP 
+\fBEFAULT\fP
+引き数が呼び出したプロセスのアドレス空間外を指している。
+.TP 
+\fBEINVAL\fP
+結果用のバッファーが小さすぎる。
+.TP 
+\fBENOENT\fP
+そのようなディレクトリは存在しない。
+.TP 
+\fBENOTDIR\fP
+ファイルディスクリプターがディレクトリを参照していない。
+.SH 準拠
+.\" SVr4 documents additional ENOLINK, EIO error conditions.
+SVr4.
+.SH 注意
+Library support for \fBgetdents64\fP()  was added in glibc 2.30; there is no
+glibc wrapper for \fBgetdents\fP().  Calling \fBgetdents\fP()  (or \fBgetdents64\fP()
+on earlier glibc versions) requires the use of \fBsyscall\fP(2).  In that case
+you will need to define the \fIlinux_dirent\fP or \fIlinux_dirent64\fP structure
+yourself.
+.PP
+Probably, you want to use \fBreaddir\fP(3)  instead of these system calls.
+.PP
+これらのシステムコールは \fBreaddir\fP(2)  を置き換えるものである。
+.SH 例
+.\" FIXME The example program needs to be revised, since it uses the older
+.\" getdents() system call and the structure with smaller field widths.
+下記のプログラムは \fBgetdents\fP()  の使用例を示したものである。 以下は、このプログラムを ext2 ディレクトリで実行した際に得られる
+出力の例である。
+.PP
+.in +4n
+.EX
+$\fB ./a.out /testfs/\fP
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=120 \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
+inode#    file type  d_reclen  d_off   d_name
+       2  directory    16         12  .
+       2  directory    16         24  ..
+      11  directory    24         44  lost+found
+      12  regular      16         56  a
+  228929  directory    16         68  sub
+   16353  directory    16         80  sub2
+  130817  directory    16       4096  sub3
+.EE
+.in
+.SS プログラムのソース
+\&
+.EX
+#define _GNU_SOURCE
+#include <dirent.h>     /* Defines DT_* constants */
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+
+#define handle_error(msg) \e
+        do { perror(msg); exit(EXIT_FAILURE); } while (0)
+
+struct linux_dirent {
+    unsigned long  d_ino;
+    off_t          d_off;
+    unsigned short d_reclen;
+    char           d_name[];
+};
+
+#define BUF_SIZE 1024
+
+int
+main(int argc, char *argv[])
+{
+    int fd;
+    long nread;
+    char buf[BUF_SIZE];
+    struct linux_dirent *d;
+    char d_type;
+
+    fd = open(argc > 1 ? argv[1] : ".", O_RDONLY | O_DIRECTORY);
+    if (fd == \-1)
+        handle_error("open");
+
+    for (;;) {
+        nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);
+        if (nread == \-1)
+            handle_error("getdents");
+
+        if (nread == 0)
+            break;
+
+        printf("\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- nread=%d \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\en", nread);
+        printf("inode#    file type  d_reclen  d_off   d_name\en");
+        for (long bpos = 0; bpos < nread;) {
+            d = (struct linux_dirent *) (buf + bpos);
+            printf("%8ld  ", d\->d_ino);
+            d_type = *(buf + bpos + d\->d_reclen \- 1);
+            printf("%\-10s ", (d_type == DT_REG) ?  "regular" :
+                             (d_type == DT_DIR) ?  "directory" :
+                             (d_type == DT_FIFO) ? "FIFO" :
+                             (d_type == DT_SOCK) ? "socket" :
+                             (d_type == DT_LNK) ?  "symlink" :
+                             (d_type == DT_BLK) ?  "block dev" :
+                             (d_type == DT_CHR) ?  "char dev" : "???");
+            printf("%4d %10jd  %s\en", d\->d_reclen,
+                    (intmax_t) d\->d_off, d\->d_name);
+            bpos += d\->d_reclen;
+        }
+    }
+
+    exit(EXIT_SUCCESS);
+}
+.EE
+.SH 関連項目
+\fBreaddir\fP(2), \fBreaddir\fP(3), \fBinode\fP(7)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
+\%https://www.kernel.org/doc/man\-pages/ に書かれている。
diff --git a/manual/LDP_man-pages/draft/man2/poll.2 b/manual/LDP_man-pages/draft/man2/poll.2
new file mode 100644 (file)
index 0000000..faefcfb
--- /dev/null
@@ -0,0 +1,452 @@
+.\" Copyright (C) 2006, 2019 Michael Kerrisk <mtk.manpages@gmail.com>
+.\"
+.\" %%%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
+.\"
+.\" Additions from Richard Gooch <rgooch@atnf.CSIRO.AU> and aeb, 971207
+.\" 2006-03-13, mtk, Added ppoll() + various other rewordings
+.\" 2006-07-01, mtk, Added POLLRDHUP + various other wording and
+.\"    formatting changes.
+.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
+.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
+.\"         all rights reserved.
+.\" Translated 1997-12-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
+.\" Updated & Modified 2004-05-22, Yuichi SATO <ysato444@yahoo.co.jp>
+.\" Updated & Modified 2005-01-03, Yuichi SATO
+.\" Updated & Modified 2005-10-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\" Updated 2005-12-05, Akihiro MOTOKI, Catch up to LDP man-pages 2.16
+.\" Updated 2006-04-16, Akihiro MOTOKI, Catch up to LDP man-pages 2.28
+.\" Updated 2006-07-23, Akihiro MOTOKI, Catch up to LDP man-pages 2.36
+.\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
+.\"
+.TH POLL 2 2020\-04\-11 Linux "Linux Programmer's Manual"
+.SH 名前
+poll, ppoll \- ファイルディスクリプターにおけるイベントを待つ
+.SH 書式
+.nf
+\fB#include <poll.h>\fP
+.PP
+\fBint poll(struct pollfd *\fP\fIfds\fP\fB, nfds_t \fP\fInfds\fP\fB, int \fP\fItimeout\fP\fB);\fP
+
+\fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
+\fB#include <signal.h>\fP
+\fB#include <poll.h>\fP
+.PP
+\fBint ppoll(struct pollfd *\fP\fIfds\fP\fB, nfds_t \fP\fInfds\fP\fB,\fP
+\fB        const struct timespec *\fP\fItmo_p\fP\fB, const sigset_t *\fP\fIsigmask\fP\fB);\fP
+.fi
+.SH 説明
+\fBpoll\fP()  performs a similar task to \fBselect\fP(2): it waits for one of a
+set of file descriptors to become ready to perform I/O.  The Linux\-specific
+\fBepoll\fP(7)  API performs a similar task, but offers features beyond those
+found in \fBpoll\fP().
+.PP
+監視するファイルディスクリプター集合は、 \fIfds\fP 引き数で指定する。 \fIfds\fP は、以下の型の構造体の配列である。
+.PP
+.in +4n
+.EX
+struct pollfd {
+    int   fd;         /* file descriptor */
+    short events;     /* requested events */
+    short revents;    /* returned events */
+};
+.EE
+.in
+.PP
+\fInfds\fP には、 \fIfds\fP 配列の要素数を指定する。
+.PP
+\fIfd\fP フィールドには、オープンされたファイルのファイルディスクリプターが入る。 このフィールドが負の場合、対応する \fIevents\fP
+フィールドは無視され、 \fIrevents\fP には 0 が返される。(この機能により、一つの \fBpoll\fP()
+の呼び出しで簡単にあるファイルディスクリプターを無視することができる。 単に \fIfd\fP フィールドの符号を反転するだけでよい。
+ただし、この方法はファイルディスクリプター 0 を無視するのには使用できない点に注意すること。)
+.PP
+構造体の \fIevents\fP 要素は入力パラメーターで、 ファイルディスクリプター \fIfd\fP に関して、
+アプリケーションが興味を持っているイベントのビットマスクを指定する。 このフィールドには 0 を指定することもでき、 その場合 \fIrevents\fP
+で返されるイベントは \fBPOLLHUP\fP, \fBPOLLERR\fP, \fBPOLLNVAL\fP だけである (下記参照)。
+.PP
+\fIrevents\fP 要素は出力パラメーターで、実際に起こったイベントがカーネルにより設定される。 \fIrevents\fP で返されるビット列には、
+\fIevents\fP で指定したもののどれか、もしくは \fBPOLLERR\fP, \fBPOLLHUP\fP, \fBPOLLNVAL\fP のうちの一つが含まれる
+(\fBPOLLERR\fP, \fBPOLLHUP\fP, \fBPOLLNVAL\fP の 3つのビットは \fIevents\fP
+に指定しても意味がなく、対応した状態が真の場合に \fIrevents\fP に設定される)。
+.PP
+どのファイルディスクリプターにも要求したイベントが発生しておらず、 エラーも起こらない場合、 \fBpoll\fP()
+はイベントのうちいずれか一つが発生するまで停止 (block) する。
+.PP
+\fItimeout\fP 引き数は、 ファイルディスクリプターが利用可能になるまで \fBpoll\fP() が停止する時間をミリ秒で指定する。
+\fBpoll\fP() の呼び出しは以下のいずれかになるまで停止する。
+.IP \(bu 2
+ファイルディスクリプターが利用可能になる
+.IP \(bu
+呼び出しがシグナルハンドラーにより割り込まれた
+.IP \(bu
+タイムアウトが満了する
+.PP
+\fItimeout\fP 時間はシステムクロックの粒度に切り上げられ、 カーネルのスケジューリング遅延により少しだけ長くなる可能性がある点に注意すること。
+\fItimeout\fP に負の値を指定した場合、タイムアウト時間が無限大を意味する。 \fItimeout\fP を 0 に指定した場合、I/O
+可能なファイルディスクリプターがない場合であっても、 \fBpoll\fP() はすぐに返る。
+.PP
+\fIevents\fP に指定したり、 \fIrevents\fP で返されるビットは \fI<poll.h>\fP で定義されている:
+.TP 
+\fBPOLLIN\fP
+読み出し可能なデータがある。
+.TP 
+\fBPOLLPRI\fP
+There is some exceptional condition on the file descriptor.  Possibilities
+include:
+.RS
+.IP \(bu 2
+There is out\-of\-band data on a TCP socket (see \fBtcp\fP(7)).
+.IP \(bu
+A pseudoterminal master in packet mode has seen a state change on the slave
+(see \fBioctl_tty\fP(2)).
+.IP \(bu
+A \fIcgroup.events\fP file has been modified (see \fBcgroups\fP(7)).
+.RE
+.TP 
+\fBPOLLOUT\fP
+書き込みが可能になった。ただし、ソケットやパイプで利用可能な空間よりも大きなデータを書き込んだ場合には (\fBO_NONBLOCK\fP
+がセットされている場合以外は) やはり停止することになる。
+.TP 
+\fBPOLLRDHUP\fP (Linux 2.6.17 以降)
+ストリームソケットの他端が、コネクションを close したか、 コネクションの書き込み側を shutdown した。 この定義を有効にするには、
+(「どの」ヘッダーファイルをインクルードするよりも前に)  \fB_GNU_SOURCE\fP 機能検査マクロを定義しなければならない。
+.TP 
+\fBPOLLERR\fP
+Error condition (only returned in \fIrevents\fP; ignored in \fIevents\fP).  This
+bit is also set for a file descriptor referring to the write end of a pipe
+when the read end has been closed.
+.TP 
+\fBPOLLHUP\fP
+Hang up (only returned in \fIrevents\fP; ignored in \fIevents\fP).  Note that when
+reading from a channel such as a pipe or a stream socket, this event merely
+indicates that the peer closed its end of the channel.  Subsequent reads
+from the channel will return 0 (end of file)  only after all outstanding
+data in the channel has been consumed.
+.TP 
+\fBPOLLNVAL\fP
+Invalid request: \fIfd\fP not open (only returned in \fIrevents\fP; ignored in
+\fIevents\fP).
+.PP
+\fB_XOPEN_SOURCE\fP を定義してコンパイルした場合には、以下の定義も行われる。
+ただし、上記のリストにあるビット以上の情報が得られる訳ではない。
+.TP 
+\fBPOLLRDNORM\fP
+\fBPOLLIN\fP と同じ。
+.TP 
+\fBPOLLRDBAND\fP
+.\" POLLRDBAND is used in the DECnet protocol.
+優先帯域データ (priority band data) が読み出し可能である (普通は Linux では使用されない)。
+.TP 
+\fBPOLLWRNORM\fP
+\fBPOLLOUT\fP と同じ。
+.TP 
+\fBPOLLWRBAND\fP
+優先帯域データ (priority data) が書き込み可能である。
+.PP
+Linux では \fBPOLLMSG\fP も定義されているが、使用されていない。
+.SS ppoll()
+\fBpoll\fP()  と \fBppoll\fP()  の関係は \fBselect\fP(2)  と \fBpselect\fP(2)  の関係と同じようなものである:
+\fBpselect\fP(2)  と同様に、 \fBppoll\fP()  を使うと、アプリケーションはファイルディスクリプターの状態変化
+もしくはシグナルの捕捉を安全に待つことができる。
+.PP
+\fItimeout\fP 引き数の精度の違いを除くと、以下の \fBppoll\fP()  の呼び出しは、
+.PP
+.in +4n
+.EX
+ready = ppoll(&fds, nfds, tmo_p, &sigmask);
+.EE
+.in
+.PP
+次の呼び出しを \fIatomic\fP に実行するのとほぼ等価である。
+.PP
+.in +4n
+.EX
+sigset_t origmask;
+int timeout;
+
+timeout = (tmo_p == NULL) ? \-1 :
+          (tmo_p\->tv_sec * 1000 + tmo_p\->tv_nsec / 1000000);
+pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
+ready = poll(&fds, nfds, timeout);
+pthread_sigmask(SIG_SETMASK, &origmask, NULL);
+.EE
+.in
+.PP
+The above code segment is described as \fInearly\fP equivalent because whereas
+a negative \fItimeout\fP value for \fBpoll\fP()  is interpreted as an infinite
+timeout, a negative value expressed in \fI*tmo_p\fP results in an error from
+\fBppoll\fP().
+.PP
+なぜ \fBppoll\fP()  が必要なのかについての説明は \fBpselect\fP(2)  の説明を参照のこと。
+.PP
+\fIsigmask\fP 引き数に NULL が指定された場合、シグナルマスクの操作は行われない (したがって、 \fBppoll\fP()  の
+\fBpoll\fP()  との違いは \fItimeout\fP 引き数の精度だけとなる)。
+.PP
+\fItmo_p\fP 引き数は \fBppoll\fP()  が停止する時間の上限を指定するものである。 この引き数には以下の型の構造体へのポインターを指定する。
+.PP
+.in +4n
+.EX
+struct timespec {
+    long    tv_sec;         /* seconds */
+    long    tv_nsec;        /* nanoseconds */
+};
+.EE
+.in
+.PP
+\fItmo_p\fP に NULL が指定された場合、 \fBppoll\fP は無限に停止することがあり得る。
+.SH 返り値
+On success, \fBpoll\fP()  returns a nonnegative value which is the number of
+elements in the \fIpollfds\fP whose \fIrevents\fP fields have been set to a
+nonzero value (indicating an event or an error).  A return value of zero
+indicates that the system call timed out before any file descriptors became
+read.
+.PP
+On error, \-1 is returned, and \fIerrno\fP is set to indicate the cause of the
+error.
+.SH エラー
+.TP 
+\fBEFAULT\fP
+\fIfds\fP points outside the process's accessible address space.  The array
+given as argument was not contained in the calling program's address space.
+.TP 
+\fBEINTR\fP
+要求されたイベントのどれかが起こる前にシグナルが発生した。 \fBsignal\fP(7)  参照。
+.TP 
+\fBEINVAL\fP
+\fInfds\fP の値が \fBRLIMIT_NOFILE\fP を超えた。
+.TP 
+\fBEINVAL\fP
+(\fBppoll\fP())  The timeout value expressed in \fI*ip\fP is invalid (negative).
+.TP 
+\fBENOMEM\fP
+Unable to allocate memory for kernel data structures.
+.SH バージョン
+\fBpoll\fP() システムコールは Linux 2.1.23 で導入された。このシステムコールが存在しない古いカーネルでは、 glibc は
+\fBselect\fP(2) を使用して \fBpoll\fP() ラッパー関数のエミュレーションを行う。
+.PP
+\fBppoll\fP()  システムコールは カーネル 2.6.16 で Linux に追加された。 \fBppoll\fP()  ライブラリコールは glibc
+2.4 に追加された。
+.SH 準拠
+.\" FIXME .
+.\" ppoll() is proposed for inclusion in POSIX:
+.\" https://www.austingroupbugs.net/view.php?id=1263
+.\" NetBSD 3.0 has a pollts() which is like Linux ppoll().
+\fBpoll\fP() は POSIX.1\-2001 と POSIX.1\-2008 に準拠している。 \fBppoll\fP()  は Linux 固有である。
+.SH 注意
+The operation of \fBpoll\fP()  and \fBppoll\fP()  is not affected by the
+\fBO_NONBLOCK\fP flag.
+.PP
+.\" Darwin, according to a report by Jeremy Sequoia, relayed by Josh Triplett
+On some other UNIX systems, \fBpoll\fP()  can fail with the error \fBEAGAIN\fP if
+the system fails to allocate kernel\-internal resources, rather than
+\fBENOMEM\fP as Linux does.  POSIX permits this behavior.  Portable programs
+may wish to check for \fBEAGAIN\fP and loop, just as with \fBEINTR\fP.
+.PP
+いくつかの実装では、値 \-1 を持った非標準の定数 \fBINFTIM\fP が定義されており、 \fBpoll\fP()  の \fItimeout\fP
+の指定に使用できる。 この定数は glibc では定義されていない。
+.PP
+\fBpoll\fP() で監視中のファイルディスクリプターが別のスレッドによってクローズされた場合に何が起こるかの議論については、 \fBselect\fP(2)
+を参照してほしい。
+.SS "C ライブラリとカーネルの違い"
+Linux の \fBppoll\fP()  システムコールは \fItmo_p\fP 引き数を変更する。 しかし、glibc
+のラッパー関数は、システムコールに渡す timeout 引き数 としてローカル変数を使うことでこの動作を隠蔽している。 このため、glibc の
+\fBppoll\fP()  関数では \fItmo_p\fP 引き数は変更されない。
+.PP
+The raw \fBppoll\fP()  system call has a fifth argument, \fIsize_t sigsetsize\fP,
+which specifies the size in bytes of the \fIsigmask\fP argument.  The glibc
+\fBppoll\fP()  wrapper function specifies this argument as a fixed value (equal
+to \fIsizeof(kernel_sigset_t)\fP).  See \fBsigprocmask\fP(2)  for a discussion on
+the differences between the kernel and the libc notion of the sigset.
+.SH バグ
+\fBselect\fP(2)  の「バグ」の節に書かれている、誤った準備完了通知 (spurious readiness notifications)
+についての議論を参照のこと。
+.SH 例
+The program below opens each of the files named in its command\-line
+arguments and monitors the resulting file descriptors for readiness to read
+(\fBPOLLIN\fP).  The program loops, repeatedly using \fBpoll\fP()  to monitor the
+file descriptors, printing the number of ready file descriptors on return.
+For each ready file descriptor, the program:
+.IP \(bu 2
+displays the returned \fIrevents\fP field in a human\-readable form;
+.IP \(bu
+if the file descriptor is readable, reads some data from it, and displays
+that data on standard output; and
+.IP \(bu
+if the file descriptors was not readable, but some other event occurred
+(presumably \fBPOLLHUP\fP), closes the file descriptor.
+.PP
+Suppose we run the program in one terminal, asking it to open a FIFO:
+.PP
+.in +4n
+.EX
+$ \fBmkfifo myfifo\fP
+$ \fB./poll_input myfifo\fP
+.EE
+.in
+.PP
+In a second terminal window, we then open the FIFO for writing, write some
+data to it, and close the FIFO:
+.PP
+.in +4n
+.EX
+$ \fBecho aaaaabbbbbccccc > myfifo\fP
+.EE
+.in
+.PP
+In the terminal where we are running the program, we would then see:
+.PP
+.in +4n
+.EX
+Opened "myfifo" on fd 3
+About to poll()
+Ready: 1
+  fd=3; events: POLLIN POLLHUP
+    read 10 bytes: aaaaabbbbb
+About to poll()
+Ready: 1
+  fd=3; events: POLLIN POLLHUP
+    read 6 bytes: ccccc
+
+About to poll()
+Ready: 1
+  fd=3; events: POLLHUP
+    closing fd 3
+All file descriptors closed; bye
+.EE
+.in
+.PP
+In the above output, we see that \fBpoll\fP()  returned three times:
+.IP \(bu 2
+On the first return, the bits returned in the \fIrevents\fP field were
+\fBPOLLIN\fP, indicating that the file descriptor is readable, and \fBPOLLHUP\fP,
+indicating that the other end of the FIFO has been closed.  The program then
+consumed some of the available input.
+.IP \(bu
+The second return from \fBpoll\fP()  also indicated \fBPOLLIN\fP and \fBPOLLHUP\fP;
+the program then consumed the last of the available input.
+.IP \(bu
+.\"
+On the final return, \fBpoll\fP()  indicated only \fBPOLLHUP\fP on the FIFO, at
+which point the file descriptor was closed and the program terminated.
+.SS プログラムのソース
+\&
+.EX
+/* poll_input.c
+
+   Licensed under GNU General Public License v2 or later.
+*/
+#include <poll.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \e
+                        } while (0)
+
+int
+main(int argc, char *argv[])
+{
+    int nfds, num_open_fds;
+    struct pollfd *pfds;
+
+    if (argc < 2) {
+       fprintf(stderr, "Usage: %s file...\en", argv[0]);
+       exit(EXIT_FAILURE);
+    }
+
+    num_open_fds = nfds = argc \- 1;
+    pfds = calloc(nfds, sizeof(struct pollfd));
+    if (pfds == NULL)
+        errExit("malloc");
+
+    /* Open each file on command line, and add it \(aqpfds\(aq array */
+
+    for (int j = 0; j < nfds; j++) {
+        pfds[j].fd = open(argv[j + 1], O_RDONLY);
+        if (pfds[j].fd == \-1)
+            errExit("open");
+
+        printf("Opened \e"%s\e" on fd %d\en", argv[j + 1], pfds[j].fd);
+
+        pfds[j].events = POLLIN;
+    }
+
+    /* Keep calling poll() as long as at least one file descriptor is
+       open */
+
+    while (num_open_fds > 0) {
+        int ready;
+
+        printf("About to poll()\en");
+        ready = poll(pfds, nfds, \-1);
+        if (ready == \-1)
+            errExit("poll");
+
+        printf("Ready: %d\en", ready);
+
+        /* Deal with array returned by poll() */
+
+        for (int j = 0; j < nfds; j++) {
+            char buf[10];
+
+            if (pfds[j].revents != 0) {
+                printf("  fd=%d; events: %s%s%s\en", pfds[j].fd,
+                        (pfds[j].revents & POLLIN)  ? "POLLIN "  : "",
+                        (pfds[j].revents & POLLHUP) ? "POLLHUP " : "",
+                        (pfds[j].revents & POLLERR) ? "POLLERR " : "");
+
+                if (pfds[j].revents & POLLIN) {
+                    ssize_t s = read(pfds[j].fd, buf, sizeof(buf));
+                    if (s == \-1)
+                        errExit("read");
+                    printf("    read %zd bytes: %.*s\en",
+                            s, (int) s, buf);
+                } else {                /* POLLERR | POLLHUP */
+                    printf("    closing fd %d\en", pfds[j].fd);
+                    if (close(pfds[j].fd) == \-1)
+                        errExit("close");
+                    num_open_fds\-\-;
+                }
+            }
+        }
+    }
+
+    printf("All file descriptors closed; bye\en");
+    exit(EXIT_SUCCESS);
+}
+.EE
+.SH 関連項目
+\fBrestart_syscall\fP(2), \fBselect\fP(2), \fBselect_tut\fP(2), \fBepoll\fP(7),
+\fBtime\fP(7)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
+\%https://www.kernel.org/doc/man\-pages/ に書かれている。
index 1ca43e8..26baf23 100644 (file)
@@ -74,10 +74,9 @@ struct old_linux_dirent {
 .EE
 .in
 .PP
-\fId_ino\fP is an inode number.  \fId_offset\fP is the distance from the start of
-the directory to this \fIold_linux_dirent\fP.  \fId_reclen\fP is the size of
-\fId_name\fP, not counting the terminating null byte (\(aq\e0\(aq).  \fId_name\fP
-is a null\-terminated filename.
+\fId_ino\fP は inode 番号である。 \fId_offset\fP はディレクトリの最初からこの \fIold_linux_dirent\fP
+まで距離である。 \fId_reclen\fP は \fId_name\fP の大きさで、終端のヌルバイト (\(aq\e0\(aq) を含まない。
+\fId_name\fP はヌルバイトで終わるファイル名である。
 .SH 返り値
 成功した場合は、1 が返される。 ディレクトリの最後では 0 が返される。 エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
 .SH エラー
index 1610d20..d96d683 100644 (file)
@@ -53,11 +53,9 @@ abort \- プロセスの異常終了を生じさせる
 \fBvoid abort(void);\fP
 .fi
 .SH 説明
-The \fBabort\fP()  function first unblocks the \fBSIGABRT\fP signal, and then
-raises that signal for the calling process (as though \fBraise\fP(3)  was
-called).  This results in the abnormal termination of the process unless the
-\fBSIGABRT\fP signal is caught and the signal handler does not return (see
-\fBlongjmp\fP(3)).
+\fBabort\fP()  関数は、まず \fBSIGABRT\fP の禁止 (block) を解除してから、 (\fBraise\fP(3)
+が呼び出されたかのように) 呼び出し元のプロセスに \fBSIGABRT\fP シグナルを上げる。その結果、 \fBSIGABRT\fP シグナルが捕捉
+(caught) されて対応するシグナルハンドラーが 返って来ない場合以外は、プログラムの異常終了が起こる (\fBlongjmp\fP(3)  参照)。
 .PP
 \fBSIGABRT\fP シグナルが無視、または返って来るシグナルハンドラーで 捕捉されるようになっている場合であっても、 \fBabort\fP()
 関数はそのプロセスを終了する。 \fBSIGABRT\fP シグナルに対する処理方法をデフォルトに戻してから、再度 \fBSIGABRT\fP
index 47784ae..519d671 100644 (file)
@@ -63,11 +63,9 @@ prog: some_file.c:16: some_func: Assertion \`val == 0\(aq failed.
 .EE
 .in
 .PP
-If the macro \fBNDEBUG\fP is defined at the moment \fI<assert.h>\fP was
-last included, the macro \fBassert\fP()  generates no code, and hence does
-nothing at all.  It is not recommended to define \fBNDEBUG\fP if using
-\fBassert\fP()  to detect error conditions since the software may behave
-non\-deterministically.
+\fI<assert.h>\fP が最後にインクルードされた時点で、 \fBNDEBUG\fP マクロが定義されている場合、 \fBassert\fP()
+マクロは何のコードも生成せず、したがって全く何もしない。 \fBassert\fP() を使ってエラー条件を検出している場合に \fBNDEBUG\fP
+を定義するのは推奨されない。ソフトウェアの動作が非決定的になってしまう可能性があるからである。
 .SH 返り値
 値は返されない。
 .SH 属性
@@ -84,9 +82,8 @@ T}    Thread safety   MT\-Safe
 .sp 1
 .SH 準拠
 .\" See Defect Report 107 for more details.
-POSIX.1\-2001, POSIX.1\-2008, C89, C99.  In C89, \fIexpression\fP is required to
-be of type \fIint\fP and undefined behavior results if it is not, but in C99 it
-may have any scalar type.
+POSIX.1\-2001, POSIX.1\-2008, C89, C99.  C89 では \fBexpression\fP は \fIint\fP
+型であることが必要とされ、そうでない場合の動作は未定義とされていた。 しかし C99 ではどのようなスカラ値でもよいことになった。
 .SH バグ
 \fBassert\fP()  は、マクロとして実装されている。すなわち、 試されている式が副作用を持っている場合には、 マクロ \fBNDEBUG\fP
 が定義されているかどうかに依存して、プログラムの振舞いは異なるだろう。 これによって、バグ出しするときには消えてしまう
index 5004abb..b5e4b70 100644 (file)
@@ -62,10 +62,9 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参
 .SH 説明
 関数 \fBdirfd\fP()  はディレクトリストリーム \fIdirp\fP に関連づけられたファイルディスクリプターを返す。
 .PP
-This file descriptor is the one used internally by the directory stream.  As
-a result, it is useful only for functions which do not depend on or alter
-the file position, such as \fBfstat\fP(2)  and \fBfchdir\fP(2).  It will be
-automatically closed when \fBclosedir\fP(3)  is called.
+このファイルディスクリプターはディレクトリストリームが内部で使用するものである。 よって、ファイルの位置に依存せず、かつその位置を変更しない関数
+\fBfstat\fP(2)  や \fBfchdir\fP(2)  などでしか役に立たない。 このファイルディスクリプターは \fBclosedir\fP(3)
+が呼ばれたときに自動的にクローズされる。
 .SH 返り値
 On success, \fBdirfd\fP()  returns a file descriptor (a nonnegative integer).
 On error, \-1 is returned, and \fIerrno\fP is set to indicate the cause of the
index 59e0a1d..cf83e6f 100644 (file)
@@ -115,7 +115,7 @@ T}  Thread safety   MT\-Safe locale
 .\" functions first appeared in
 .\" 4.4BSD.
 これらの関数は非標準の BSD 拡張である。
-.SH EXAMPLES
+.SH 
 現在の \fIerrno\fP の情報を表示し、終了する:
 .PP
 .in +4n
diff --git a/manual/LDP_man-pages/draft/man3/errno.3 b/manual/LDP_man-pages/draft/man3/errno.3
new file mode 100644 (file)
index 0000000..2f77882
--- /dev/null
@@ -0,0 +1,590 @@
+.\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl)
+.\"
+.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
+.\" This is free documentation; you can redistribute it and/or
+.\" modify it under the terms of the GNU General Public License as
+.\" published by the Free Software Foundation; either version 2 of
+.\" the License, or (at your option) any later version.
+.\"
+.\" The GNU General Public License's references to "object code"
+.\" and "executables" are to be interpreted as the output of any
+.\" document formatting or typesetting system, including
+.\" intermediate and printed output.
+.\"
+.\" This manual is distributed in the hope that it will be useful,
+.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public
+.\" License along with this manual; if not, see
+.\" <http://www.gnu.org/licenses/>.
+.\" %%%LICENSE_END
+.\"
+.\" 5 Oct 2002, Modified by Michael Kerrisk <mtk.manpages@gmail.com>
+.\"    Updated for POSIX.1 2001
+.\" 2004-12-17 Martin Schulze <joey@infodrom.org>, mtk
+.\"    Removed errno declaration prototype, added notes
+.\" 2006-02-09 Kurt Wall, mtk
+.\"     Added non-POSIX errors
+.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
+.\" Japanese Version Copyright (c) 1997 HIROFUMI Nishizuka
+.\"     all rights reserved.
+.\" Translated 1997-12-24, HIROFUMI Nishizuka <nishi@rpts.cl.nec.co.jp>
+.\" Updated 1999-03-01, NAKANO Takeo <nakano@apm.seikei.ac.jp>
+.\" Updated 1999-08-21, NAKANO Takeo <nakano@apm.seikei.ac.jp>
+.\" Updated 2003-07-03, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\" Updated 2005-03-15, Akihiro MOTOKI
+.\" Updated 2006-02-15, Akihiro MOTOKI, Catch up to LDP v2.23
+.\" Updated 2006-07-14, Akihiro MOTOKI, Catch up to LDP v2.34
+.\" Updated 2008-08-07, Akihiro MOTOKI, Catch up to LDP v3.05
+.\"
+.TH ERRNO 3 2020\-11\-01 "" "Linux Programmer's Manual"
+.SH 名前
+errno \- 直近に発生したエラーの番号
+.SH 書式
+.\".PP
+.\".BI "extern int " errno ;
+\fB#include <errno.h>\fP
+.SH 説明
+.\"
+ヘッダーファイル \fI<errno.h>\fP で整数型の変数 \fIerrno\fP が定義されており、
+システムコールやいくつかのライブラリ関数は、エラーが発生した際に この変数にその原因を示す値を設定する。
+.SS errno
+\fIerrno\fP の値は呼び出しの返り値がエラー (ほとんどのシステムコールでは \-1 で、ほとんどのライブラリ関数では \-1 か NULL)
+を示したときにのみ意味を持つが、関数は成功した場合も \fIerrno\fP を変更することが「許されている」。どのシステムコールもライブラリ関数も
+\fIerrno\fP の値を 0 に設定することはない。
+.PP
+いくつかのシステムコールやライブラリ関数 (例えば \fBgetpriority\fP(2))  では、成功した場合の有効な返り値として \-1
+が返されることがある。 このような場合、成功なのかエラーなのかを区別するためには、 呼び出しの前に \fIerrno\fP を 0
+に設定しておけばよい。呼び出しの返り値がエラー発生の可能性を 示すものだった場合には、 \fIerrno\fP が 0 以外の値かを見て確認すればよい。
+.PP
+.\"
+\fIerrno\fP は、ISO C standard で \fIint\fP 型の変更可能な左辺値 として定義されており、明示的に宣言を行ってはならない;
+\fIerrno\fP はマクロの場合もありえる。 \fIerrno\fP はスレッド毎に値を持つ。 つまりあるスレッドで \fIerrno\fP が設定されても、
+他のスレッドの \fIerrno\fP には影響しない。
+.SS "Error numbers and names"
+Valid error numbers are all positive numbers.  The \fI<errno.h>\fP
+header file defines symbolic names for each of the possible error numbers
+that may appear in \fIerrno\fP.
+.PP
+POSIX.1 で定義されているすべてのエラー名には、 それぞれ異なる値が対応していなければならない。 但し、 \fBEAGAIN\fP と
+\fBEWOULDBLOCK\fP は例外で、これらは同じ値を持ってもよい。 Linux では、すべてのアーキテクチャーでこれら二つは同じ値である。
+.PP
+The error numbers that correspond to each symbolic name vary across UNIX
+systems, and even across different architectures on Linux.  Therefore,
+numeric values are not included as part of the list of error names below.
+The \fBperror\fP(3)  and \fBstrerror\fP(3)  functions can be used to convert these
+names to corresponding textual error messages.
+.PP
+On any particular Linux system, one can obtain a list of all symbolic error
+names and the corresponding error numbers using the \fBerrno\fP(1)  command
+(part of the \fImoreutils\fP package):
+.PP
+.in +4n
+.EX
+$ \fBerrno \-l\fP
+EPERM 1 Operation not permitted
+ENOENT 2 No such file or directory
+ESRCH 3 No such process
+EINTR 4 Interrupted system call
+EIO 5 Input/output error
+\&...
+.EE
+.in
+.PP
+The \fBerrno\fP(1)  command can also be used to look up individual error
+numbers and names, and to search for errors using strings from the error
+description, as in the following examples:
+.PP
+.in +4n
+.EX
+$ \fBerrno 2\fP
+ENOENT 2 No such file or directory
+$ \fBerrno ESRCH\fP
+ESRCH 3 No such process
+$ \fBerrno \-s permission\fP
+EACCES 13 Permission denied
+.EE
+.in
+.\".PP
+.\" POSIX.1 (2001 edition) lists the following symbolic error names.  Of
+.\" these, \fBEDOM\fP and \fBERANGE\fP are in the ISO C standard.  ISO C
+.\" Amendment 1 defines the additional error number \fBEILSEQ\fP for
+.\" coding errors in multibyte or wide characters.
+.\"
+.SS "List of error names"
+In the list of the symbolic error names below, various names are marked as
+follows:
+.IP * 3
+\fIPOSIX.1\-2001\fP: The name is defined by POSIX.1\-2001, and is defined in
+later POSIX.1 versions, unless otherwise indicated.
+.IP *
+\fIPOSIX.1\-2008\fP: The name is defined in POSIX.1\-2008, but was not present in
+earlier POSIX.1 standards.
+.IP *
+\fIC99\fP: The name is defined by C99.
+.PP
+Below is a list of the symbolic error names that are defined on Linux:
+.TP  16
+\fBE2BIG\fP
+引き数リストが長過ぎる (POSIX.1\-2001)
+.TP 
+\fBEACCES\fP
+許可がない (POSIX.1\-2001)
+.TP 
+\fBEADDRINUSE\fP
+アドレスがすでに使用されている (POSIX.1\-2001)
+.TP 
+\fBEADDRNOTAVAIL\fP
+.\" EADV is only an error on HURD(?)
+アドレスが使用できない (POSIX.1\-2001)
+.TP 
+\fBEAFNOSUPPORT\fP
+アドレスファミリーがサポートされていない (POSIX.1\-2001)
+.TP 
+\fBEAGAIN\fP
+リソースが一時的に利用不可 (\fBEWOULDBLOCK\fP と同じ値でもよい) (POSIX.1\-2001)
+.TP 
+\fBEALREADY\fP
+接続が既に処理中である (POSIX.1\-2001)
+.TP 
+\fBEBADE\fP
+不正なやり取り (exchange) である
+.TP 
+\fBEBADF\fP
+ファイルディスクリプターが不正である (POSIX.1\-2001)
+.TP 
+\fBEBADFD\fP
+ファイルディスクリプターが不正な状態である
+.TP 
+\fBEBADMSG\fP
+メッセージが不正である (POSIX.1\-2001)
+.TP 
+\fBEBADR\fP
+不正なリクエストディスクリプター
+.TP 
+\fBEBADRQC\fP
+不正なリクエストコード
+.TP 
+\fBEBADSLT\fP
+.\" EBFONT is defined but appears not to be used by kernel or glibc.
+不正なスロット
+.TP 
+\fBEBUSY\fP
+リソースが使用中である (POSIX.1\-2001)
+.TP 
+\fBECANCELED\fP
+操作がキャンセルされた (POSIX.1\-2001)
+.TP 
+\fBECHILD\fP
+子プロセスが無い (POSIX.1\-2001)
+.TP 
+\fBECHRNG\fP
+チャンネル番号が範囲外である
+.TP 
+\fBECOMM\fP
+送信時に通信エラーが発生した
+.TP 
+\fBECONNABORTED\fP
+接続が中止された (POSIX.1\-2001)
+.TP 
+\fBECONNREFUSED\fP
+接続が拒否された (POSIX.1\-2001)
+.TP 
+\fBECONNRESET\fP
+接続がリセットされた (POSIX.1\-2001)
+.TP 
+\fBEDEADLK\fP
+リソースのデッドロックを回避した (POSIX.1\-2001)
+.TP 
+\fBEDEADLOCK\fP
+On most architectures, a synonym for \fBEDEADLK\fP.  On some architectures
+(e.g., Linux MIPS, PowerPC, SPARC), it is a separate error code "File
+locking deadlock error".
+.TP 
+\fBEDESTADDRREQ\fP
+宛先アドレスが必要である (POSIX.1\-2001)
+.TP 
+\fBEDOM\fP
+.\" EDOTDOT is defined but appears to be unused
+数学関数で引き数が領域外 (out of domain) である (POSIX.1, C99)
+.TP 
+\fBEDQUOT\fP
+.\" POSIX just says "Reserved"
+ディスククォータ (quota) を超過した (POSIX.1\-2001)
+.TP 
+\fBEEXIST\fP
+ファイルが存在する (POSIX.1\-2001)
+.TP 
+\fBEFAULT\fP
+アドレスが不正である (POSIX.1\-2001)
+.TP 
+\fBEFBIG\fP
+ファイルが大き過ぎる (POSIX.1\-2001)
+.TP 
+\fBEHOSTDOWN\fP
+ホストがダウンしている
+.TP 
+\fBEHOSTUNREACH\fP
+ホストに到達不能である (POSIX.1\-2001)
+.TP 
+\fBEHWPOISON\fP
+Memory page has hardware error.
+.TP 
+\fBEIDRM\fP
+識別子が削除された (POSIX.1\-2001)
+.TP 
+\fBEILSEQ\fP
+Invalid or incomplete multibyte or wide character (POSIX.1, C99).
+.IP
+The text shown here is the glibc error description; in POSIX.1, this error
+is described as "Illegal byte sequence".
+.TP 
+\fBEINPROGRESS\fP
+操作が実行中である (POSIX.1\-2001)
+.TP 
+\fBEINTR\fP
+関数呼び出しが割り込まれた (POSIX.1\-2001); \fBsignal\fP(7)  参照。
+.TP 
+\fBEINVAL\fP
+引数が無効である (POSIX.1\-2001)
+.TP 
+\fBEIO\fP
+入出力エラー (POSIX.1\-2001)
+.TP 
+\fBEISCONN\fP
+ソケットが接続されている (POSIX.1\-2001)
+.TP 
+\fBEISDIR\fP
+ディレクトリである (POSIX.1\-2001)
+.TP 
+\fBEISNAM\fP
+名前付きのファイルである
+.TP 
+\fBEKEYEXPIRED\fP
+鍵が期限切れとなった
+.TP 
+\fBEKEYREJECTED\fP
+鍵がサーバにより拒否された
+.TP 
+\fBEKEYREVOKED\fP
+鍵が無効となった
+.TP 
+\fBEL2HLT\fP
+停止 (レベル 2)
+.TP 
+\fBEL2NSYNC\fP
+同期できていない (レベル 2)
+.TP 
+\fBEL3HLT\fP
+停止 (レベル 3)
+.TP 
+\fBEL3RST\fP
+停止 (レベル 3)
+.TP 
+\fBELIBACC\fP
+必要な共有ライブラリにアクセスできなかった
+.TP 
+\fBELIBBAD\fP
+壊れた共有ライブラリにアクセスしようとした
+.TP 
+\fBELIBMAX\fP
+リンクしようとした共有ライブラリが多過ぎる
+.TP 
+\fBELIBSCN\fP
+a.out の \&.lib セクションが壊れている (corrupted)
+.TP 
+\fBELIBEXEC\fP
+共有ライブラリを直接実行できなかった
+.TP 
+\fBELNRANGE\fP
+.\" ELNRNG appears to be used by a few drivers
+リンク番号が範囲外である
+.TP 
+\fBELOOP\fP
+シンボリックリンクの回数が多過ぎる (POSIX.1\-2001)
+.TP 
+\fBEMEDIUMTYPE\fP
+間違ったメディア種別である
+.TP 
+\fBEMFILE\fP
+オープンしているファイルが多過ぎる (POSIX.1\-2001)。 通常は \fBgetrlimit\fP(2) に説明があるリソース上限
+\fBRLIMIT_NOFILE\fP を超過した場合に発生する。 \fI/proc/sys/fs/nr_open\fP
+で指定された上限を超過した場合にも発生する。
+.TP 
+\fBEMLINK\fP
+リンクが多過ぎる (POSIX.1\-2001)
+.TP 
+\fBEMSGSIZE\fP
+メッセージが長過ぎる (POSIX.1\-2001)
+.TP 
+\fBEMULTIHOP\fP
+.\" POSIX says "Reserved"
+マルチホップ (multihop) を試みた (POSIX.1\-2001)
+.TP 
+\fBENAMETOOLONG\fP
+.\" ENAVAIL is defined, but appears not to be used
+ファイル名が長過ぎる (POSIX.1\-2001)
+.TP 
+\fBENETDOWN\fP
+ネットワークが不通である (POSIX.1\-2001)
+.TP 
+\fBENETRESET\fP
+接続がネットワーク側から中止された (POSIX.1\-2001)
+.TP 
+\fBENETUNREACH\fP
+ネットワークが到達不能である (POSIX.1\-2001)
+.TP 
+\fBENFILE\fP
+Too many open files in system (POSIX.1\-2001).  On Linux, this is probably a
+result of encountering the \fI/proc/sys/fs/file\-max\fP limit (see \fBproc\fP(5)).
+.TP 
+\fBENOANO\fP
+.\" ENOANO appears to be used by a few drivers
+No anode.
+.TP 
+\fBENOBUFS\fP
+.\" ENOCSI is defined but appears to be unused.
+使用可能なバッファー空間がない (POSIX.1 (XSI STREAMS オプション))
+.TP 
+\fBENODATA\fP
+ストリームの読み出しキューの先頭に読み出し可能なメッセージがない (POSIX.1\-2001)
+.TP 
+\fBENODEV\fP
+そのようなデバイスは無い (POSIX.1\-2001)
+.TP 
+\fBENOENT\fP
+そのようなファイルやディレクトリは無い (POSIX.1\-2001)
+.IP
+Typically, this error results when a specified pathname does not exist, or
+one of the components in the directory prefix of a pathname does not exist,
+or the specified pathname is a dangling symbolic link.
+.TP 
+\fBENOEXEC\fP
+実行ファイル形式のエラー (POSIX.1\-2001)
+.TP 
+\fBENOKEY\fP
+要求された鍵が利用できない
+.TP 
+\fBENOLCK\fP
+利用できるロックが無い (POSIX.1\-2001)
+.TP 
+\fBENOLINK\fP
+.\" POSIX says "Reserved"
+リンクが切れている (POSIX.1\-2001)
+.TP 
+\fBENOMEDIUM\fP
+メディアが見つからない
+.TP 
+\fBENOMEM\fP
+十分な空きメモリー領域が無い/メモリを割り当てることができない (POSIX.1\-2001)
+.TP 
+\fBENOMSG\fP
+要求された型のメッセージが存在しない (POSIX.1\-2001)
+.TP 
+\fBENONET\fP
+マシンがネットワーク上にない
+.TP 
+\fBENOPKG\fP
+パッケージがインストールされていない
+.TP 
+\fBENOPROTOOPT\fP
+指定されたプロトコルが利用できない (POSIX.1\-2001)
+.TP 
+\fBENOSPC\fP
+デバイスに空き領域が無い (POSIX.1\-2001)
+.TP 
+\fBENOSR\fP
+指定されたストリームリソースが存在しない (POSIX.1 (XSI STREAMS オプション))
+.TP 
+\fBENOSTR\fP
+ストリームではない (POSIX.1 (XSI STREAMS オプション))
+.TP 
+\fBENOSYS\fP
+関数が実装されていない (POSIX.1\-2001)
+.TP 
+\fBENOTBLK\fP
+ブロックデバイスが必要である
+.TP 
+\fBENOTCONN\fP
+ソケットが接続されていない (POSIX.1\-2001)
+.TP 
+\fBENOTDIR\fP
+ディレクトリではない (POSIX.1\-2001)
+.TP 
+\fBENOTEMPTY\fP
+.\" ENOTNAM is defined but appears to be unused.
+ディレクトリが空ではない (POSIX.1\-2001)
+.TP 
+\fBENOTRECOVERABLE\fP
+State not recoverable (POSIX.1\-2008).
+.TP 
+\fBENOTSOCK\fP
+ソケットではない (POSIX.1\-2001)
+.TP 
+\fBENOTSUP\fP
+操作がサポートされていない (POSIX.1\-2001)
+.TP 
+\fBENOTTY\fP
+I/O 制御操作が適切でない (POSIX.1\-2001)
+.TP 
+\fBENOTUNIQ\fP
+名前がネットワークで一意ではない
+.TP 
+\fBENXIO\fP
+そのようなデバイスやアドレスはない (POSIX.1\-2001)
+.TP 
+\fBEOPNOTSUPP\fP
+ソケットでサポートしていない操作である (POSIX.1\-2001)
+.IP
+(Linux では \fBENOTSUP\fP と \fBEOPNOTSUPP\fP は同じ値を持つが、 POSIX.1
+に従えば両者のエラー値は区別されるべきである。)
+.TP 
+\fBEOVERFLOW\fP
+指定されたデータ型に格納するには値が大き過ぎる (POSIX.1\-2001)
+.TP 
+\fBEOWNERDEAD\fP
+.\" Used at least by the user-space side of rubost mutexes
+Owner died (POSIX.1\-2008).
+.TP 
+\fBEPERM\fP
+操作が許可されていない (POSIX.1\-2001)
+.TP 
+\fBEPFNOSUPPORT\fP
+サポートされていないプロトコルファミリーである
+.TP 
+\fBEPIPE\fP
+パイプが壊れている (POSIX.1\-2001)
+.TP 
+\fBEPROTO\fP
+プロトコルエラー (POSIX.1\-2001)
+.TP 
+\fBEPROTONOSUPPORT\fP
+プロトコルがサポートされていない (POSIX.1\-2001)
+.TP 
+\fBEPROTOTYPE\fP
+ソケットに指定できないプロトコルタイプである (POSIX.1\-2001)
+.TP 
+\fBERANGE\fP
+結果が大き過ぎる (POSIX.1, C99)
+.TP 
+\fBEREMCHG\fP
+リモートアドレスが変わった
+.TP 
+\fBEREMOTE\fP
+オブジェクトがリモートにある
+.TP 
+\fBEREMOTEIO\fP
+リモート I/O エラー
+.TP 
+\fBERESTART\fP
+システムコールが中断され再スタートが必要である
+.TP 
+\fBERFKILL\fP
+.\" ERFKILL appears to be used by various drivers
+Operation not possible due to RF\-kill.
+.TP 
+\fBEROFS\fP
+読み出し専用のファイルシステムである (POSIX.1\-2001)
+.TP 
+\fBESHUTDOWN\fP
+通信相手がシャットダウンされて送信できない
+.TP 
+\fBESPIPE\fP
+無効なシーク (POSIX.1\-2001)
+.TP 
+\fBESOCKTNOSUPPORT\fP
+サポートされていないソケット種別である
+.TP 
+\fBESRCH\fP
+.\" ESRMNT is defined but appears not to be used
+そのようなプロセスは無い (POSIX.1\-2001)
+.TP 
+\fBESTALE\fP
+ファイルハンドルが古い状態になっている (POSIX.1\-2001)
+.IP
+NFS や他のファイルシステムで起こりうる。
+.TP 
+\fBESTRPIPE\fP
+ストリームパイプエラー
+.TP 
+\fBETIME\fP
+時間が経過した (POSIX.1 (XSI STREAMS option))
+.IP
+(POSIX.1 では "STREAM \fBioctl\fP(2)  timeout" と書かれている)
+.TP 
+\fBETIMEDOUT\fP
+操作がタイムアウトした (POSIX.1\-2001)
+.TP 
+\fBETOOMANYREFS\fP
+.\" ETOOMANYREFS seems to be used in net/unix/af_unix.c
+Too many references: cannot splice.
+.TP 
+\fBETXTBSY\fP
+テキストファイルが使用中である (POSIX.1\-2001)
+.TP 
+\fBEUCLEAN\fP
+Structure needs cleaning.
+.TP 
+\fBEUNATCH\fP
+プロトコルのドライバが付与 (attach) されていない
+.TP 
+\fBEUSERS\fP
+ユーザー数が多過ぎる
+.TP 
+\fBEWOULDBLOCK\fP
+操作がブロックされる見込みである (\fBEAGAIN\fP と同じ値でもよい) (POSIX.1\-2001)
+.TP 
+\fBEXDEV\fP
+不適切なリンク (POSIX.1\-2001)
+.TP 
+\fBEXFULL\fP
+変換テーブルが一杯である
+.SH 注意
+以下はよくやる間違いである。
+.PP
+.in +4n
+.EX
+if (somecall() == \-1) {
+    printf("somecall() failed\en");
+    if (errno == ...) { ... }
+}
+.EE
+.in
+.PP
+このようにすると、参照している時点では \fIerrno\fP はもはや \fIsomecall\fP()  から返された値を保持しているとは限らない
+(\fBprintf\fP(3)  により変更されているかもしれない)。 ライブラリコールをまたいで \fIerrno\fP
+の値を保存したい場合は、以下のように保存しなければならない:
+.PP
+.in +4n
+.EX
+if (somecall() == \-1) {
+    int errsv = errno;
+    printf("somecall() failed\en");
+    if (errsv == ...) { ... }
+}
+.EE
+.in
+.PP
+Note that the POSIX threads APIs do \fInot\fP set \fIerrno\fP on error.  Instead,
+on failure they return an error number as the function result.  These error
+numbers have the same meanings as the error numbers returned in \fIerrno\fP by
+other APIs.
+.PP
+On some ancient systems, \fI<errno.h>\fP was not present or did not
+declare \fIerrno\fP, so that it was necessary to declare \fIerrno\fP manually
+(i.e., \fIextern int errno\fP).  \fBDo not do this\fP.  It long ago ceased to be
+necessary, and it will cause problems with modern versions of the C library.
+.SH 関連項目
+.\" In the moreutils package
+\fBerrno\fP(1), \fBerr\fP(3), \fBerror\fP(3), \fBperror\fP(3), \fBstrerror\fP(3)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
+\%https://www.kernel.org/doc/man\-pages/ に書かれている。
index d505b38..5df80c8 100644 (file)
@@ -47,9 +47,9 @@ glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参
 .RE
 .PP
 \fBgetdirentries\fP():
-    Since glibc 2.19:
+    glibc 2.19 以降:
         _DEFAULT_SOURCE
-    Glibc 2.19 and earlier:
+    glibc 2.19 以前:
         _BSD_SOURCE || _SVID_SOURCE
 .SH 説明
 \fIfd\fP で指定されたディレクトリからエントリーを読み、 \fIbuf\fP に格納する。最大で \fInbytes\fP が読み込まれる。読み込みはオフセット
@@ -71,8 +71,8 @@ T{
 T}     Thread safety   MT\-Safe
 .TE
 .SH 準拠
-Not in POSIX.1.  Present on the BSDs, and a few other systems.  Use
-\fBopendir\fP(3)  and \fBreaddir\fP(3)  instead.
+POSIX.1 にはない。 BSD に存在し、他にもいくつかのシステムにもある。 代わりに \fBopendir\fP(3)  と \fBreaddir\fP(3)
+を使用すること。
 .SH 関連項目
 \fBlseek\fP(2), \fBopen\fP(2)
 .SH この文書について
index 1a72d8c..6e0e3ba 100644 (file)
@@ -211,7 +211,7 @@ were typed as \fIconst void\ *\fP.  When \fBalphasort\fP()  was standardized in
 POSIX.1\-2008, the argument type was specified as the type\-safe \fIconst
 struct dirent\ **\fP, and glibc 2.10 changed the definition of \fBalphasort\fP()
 (and the nonstandard \fBversionsort\fP())  to match the standard.
-.SH EXAMPLES
+.SH 
 .\"
 The program below prints a list of the files in the current directory in
 reverse order.
diff --git a/manual/LDP_man-pages/draft/man7/epoll.7 b/manual/LDP_man-pages/draft/man7/epoll.7
new file mode 100644 (file)
index 0000000..5160940
--- /dev/null
@@ -0,0 +1,356 @@
+.\"  Copyright (C) 2003  Davide Libenzi
+.\"
+.\" %%%LICENSE_START(GPLv2+_SW_3_PARA)
+.\"  This program is free software; you can redistribute it and/or modify
+.\"  it under the terms of the GNU General Public License as published by
+.\"  the Free Software Foundation; either version 2 of the License, or
+.\"  (at your option) any later version.
+.\"
+.\"  This program is distributed in the hope that it will be useful,
+.\"  but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\"  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+.\"  GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public
+.\" License along with this manual; if not, see
+.\" <http://www.gnu.org/licenses/>.
+.\" %%%LICENSE_END
+.\"
+.\"  Davide Libenzi <davidel@xmailserver.org>
+.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
+.\" Japanese Version Copyright (c) 2004-2005 Yuichi SATO
+.\"         all rights reserved.
+.\" Translated Sat Jun 19 07:50:04 JST 2004
+.\"         by Yuichi SATO <ysato444@yahoo.co.jp>
+.\" Updated & Modified 2005-01-18, Yuichi SATO
+.\" Updated 2006-07-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\"         Catch up to LDP v2.34. epoll.4 is renamed to epoll.7.
+.\" Updated 2007-09-07, Akihiro MOTOKI, LDP v2.64
+.\" Updated 2008-04-08, Akihiro MOTOKI, LDP v2.79
+.\" Updated 2009-02-23, Akihiro MOTOKI, LDP v3.19
+.\"
+.TH EPOLL 7 2019\-03\-06 Linux "Linux Programmer's Manual"
+.SH 名前
+epoll \- I/O イベント通知機能
+.SH 書式
+\fB#include <sys/epoll.h>\fP
+.SH 説明
+\fBepoll\fP API は \fBpoll\fP(2)
+と同様の処理を行う、つまり、複数のファイルディスクリプタを監視し、その中のいずれかが入出力可能な状態であるかを確認する。 \fBepoll\fP API
+は、エッジトリガーインターフェースとレベルトリガーインターフェースのいずれとしても使用することができ、監視するファイルディスクリプターの数が多い場合にも使用できる。
+.PP
+The central concept of the \fBepoll\fP API is the \fBepoll\fP \fIinstance\fP, an
+in\-kernel data structure which, from a user\-space perspective, can be
+considered as a container for two lists:
+.IP \(bu 2
+The \fIinterest\fP list (sometimes also called the \fBepoll\fP set): the set of
+file descriptors that the process has registered an interest in monitoring.
+.IP \(bu
+The \fIready\fP list: the set of file descriptors that are "ready" for I/O.
+The ready list is a subset of (or, more precisely, a set of references to)
+the file descriptors in the interest list.  The ready list is dynamically
+populated by the kernel as a result of I/O activity on those file
+descriptors.
+.PP
+The following system calls are provided to create and manage an \fBepoll\fP
+instance:
+.IP \(bu 2
+\fBepoll_create\fP(2) は新規の \fBepoll\fP インスタンスを作成し、そのインスタンスを参照する
+ファイルディスクリプターを返す。(もっと新しい \fBepoll_create1\fP(2) では、
+\fBepoll_create\fP(2) の機能が拡張されている)。
+.IP \(bu
+Interest in particular file descriptors is then registered via
+\fBepoll_ctl\fP(2), which adds items to the interest list of the \fBepoll\fP
+instance.
+.IP \(bu
+.\"
+\fBepoll_wait\fP(2)  waits for I/O events, blocking the calling thread if no
+events are currently available.  (This system call can be thought of as
+fetching items from the ready list of the \fBepoll\fP instance.)
+.SS レベルトリガーとエッジトリガー
+\fBepoll\fP イベント配送 (distribution) インターフェースは、 エッジトリガー (ET) としてもレベルトリガー (LT)
+としても動作させることができる。 二つの配送機構の違いは、次のように説明できる。 このようなシナリオが起こったとしよう:
+.IP 1. 3
+パイプの読み込み側を表すファイルディスクリプター (\fIrfd\fP)  が \fBepoll\fP インスタンスに登録される。
+.IP 2.
+パイプへ書き込むプログラムが 2\ kB のデータをパイプの書き込み側へ書き込む。
+.IP 3.
+\fBepoll_wait\fP(2)  を呼び出すと、読み込み可能 (ready) なファイルディスクリプターとして \fIrfd\fP が返る。
+.IP 4.
+パイプから読み出すプログラムが、1\ kB のデータを \fIrfd\fP から読み出す。
+.IP 5.
+\fBepoll_wait\fP(2)  の呼び出しが行われる。
+.PP
+\fIrfd\fP ファイルディスクリプターが \fBEPOLLET\fP フラグ (エッジトリガー) を使って \fBepoll\fP に追加されていると、
+利用可能なデータがファイル入力バッファーにまだ存在するにもかかわらず ステップ \fB5\fP の \fBepoll_wait\fP(2)
+の呼び出しでハングする可能性がある。 その一方で、リモートの接続先 (peer) は既に送られたデータに 基づいて応答を期待しているかもしれない。
+このようなことが起こる理由は、エッジトリガーイベント配送では、 モニタしているファイルでイベントが起ったときにのみイベントが 配送されるためである。
+したがって、ステップ \fB5\fP では、呼び出し側は結果的に 入力バッファー内にすで存在するデータを待つことになるかもしれない。 上記の例では、 \fB2\fP
+で行われた書き込みによって \fIrfd\fP に関するイベントが生成され、 \fB3\fP でイベントが消費 (consume) される。 \fB4\fP
+で行われる読み込み操作では、全部のバッファーデータを消費しないので、 ステップ \fB5\fP で行われる \fBepoll_wait\fP(2)  の呼び出しが
+無期限に停止 (block) するかもしれない。
+.PP
+\fBEPOLLET\fP フラグを採用するアプリケーションでは、 インターフェースはブロックしない (nonblocking) ファイルディスクリプターを
+使うべきである。 これは、ブロックされる読み込みや書き込みによって、 複数のファイルディスクリプターを扱うタスクが 停止してしまうのを避けるためである。
+\fBepoll\fP をエッジトリガー (\fBEPOLLET\fP)  インターフェースとして使うために提案される方法は以下の通りである。
+.IP a) 3
+ブロックしないファイルディスクリプターと共に使う。
+.IP b)
+\fBread\fP(2)  または \fBwrite\fP(2)  が \fBEAGAIN\fP を返した後でのみ、イベントを待つ。
+.PP
+一方、レベルトリガーインターフェースとして使う場合
+ (こちらがデフォルトである、
+\fBEPOLLET\fP が指定されなかった場合)、
+\fBepoll\fP は単に高速な \fBpoll\fP(2) であり、使い方が同じなので、
+\fBpoll\fP(2) が使われているところではどこでも使用することができる。
+.PP
+エッジトリガーを使った場合でも、複数のデータを受信すると複数の \fBepoll\fP イベントが生成されるので、 呼び出し側には
+\fBEPOLLONESHOT\fP フラグを指定するオプションがある。 このフラグは \fBepoll\fP に対して、 \fBepoll_wait\fP(2)
+によるイベントを受信した後で、関連するファイルディスクリプターを無効にさせる。 \fBEPOLLONESHOT\fP フラグが指定された場合、
+\fBepoll_ctl\fP(2)  に \fBEPOLL_CTL_MOD\fP を指定してファイルディスクリプターを再度使用できるようにするのは、
+呼び出し側の責任である。
+.PP
+.\"
+If multiple threads (or processes, if child processes have inherited the
+\fBepoll\fP file descriptor across \fBfork\fP(2))  are blocked in \fBepoll_wait\fP(2)
+waiting on the same epoll file descriptor and a file descriptor in the
+interest list that is marked for edge\-triggered (\fBEPOLLET\fP)  notification
+becomes ready, just one of the threads (or processes) is awoken from
+\fBepoll_wait\fP(2).  This provides a useful optimization for avoiding
+"thundering herd" wake\-ups in some scenarios.
+.SS "autosleep との関係"
+システムが \fI/sys/power/autosleep\fP 経由で \fBautosleep\fP モードになっていて、
+デバイスをスリープ状態から起こすイベントが発生した場合、 デバイスドライバーはデバイスを起こしておくのはそのイベントがキューに入るまでだけである。
+イベントが処理されるまでデバイスを起こしたままにしておくには、 \fBepoll_ctl\fP(2) \fBEPOLLWAKEUP\fP フラグを使う必要がある。
+.PP
+\fBEPOLLWAKEUP\fP フラグが \fIstruct epoll_event\fP の \fBevents\fP フィールドでセットされた場合、
+イベントがキューに入った瞬間から、\fBepoll_wait\fP(2) がそのイベントを返し次の \fBepoll_wait\fP(2)
+の呼び出しが行われるまでの間、システムは起きたままの状態になる。
+イベントが上記の時間の範囲を超えてシステムを起きたままの状態にしておく必要がある場合は、 2 番目の \fBepoll_wait\fP(2)
+の呼び出しの前に別の \fIwake_lock\fP を取る必要がある。
+.SS "/proc インターフェース"
+.\" Following was added in 2.6.28, but them removed in 2.6.29
+.\" .TP
+.\" .IR /proc/sys/fs/epoll/max_user_instances " (since Linux 2.6.28)"
+.\" This specifies an upper limit on the number of epoll instances
+.\" that can be created per real user ID.
+epoll が消費するカーネルメモリーの量を制限するために、 以下のインターフェースを使用することができる。
+.TP 
+\fI/proc/sys/fs/epoll/max_user_watches\fP (Linux 2.6.28 以降)
+.\" 2.6.29 (in 2.6.28, the default was 1/32 of lowmem)
+このファイルは、あるユーザーがシステム上の全ての epoll インスタンスに 登録できるファイルディスクリプターの総数の上限を規定する。
+この上限は実ユーザー ID 単位である。 登録されたファイルディスクリプター 1 つが消費するメモリー量は、 32 ビットカーネルでおよそ 90
+バイト、 64 ビットカーネルでおよそ 160 バイトである。 現在のところ、 \fImax_user_watches\fP
+のデフォルト値は、利用可能なメモリー下限の 1/25 (4%) であり、 登録で消費されるメモリー量 (バイト単位) で割った値となる。
+.SS おすすめな使用例
+レベルトリガーインターフェースとして使用するときの \fBepoll\fP の使い方は \fBpoll\fP(2)  と同じである。
+しかしエッジトリガーとして使う場合は、 アプリケーションのイベントループでストール (stall) しないように、
+使い方をより明確にしておく必要がある。 この例では、リスナはブロックしないソケットであり、 \fBlisten\fP(2)  が呼ばれている。 関数
+\fIdo_use_fd()\fP は、 \fBread\fP(2)  または \fBwrite\fP(2)  によって \fBEAGAIN\fP
+が返されるまでは、新しい準備済みのファイルディスクリプターを使う。 イベント駆動ステートマシンアプリケーションは、 \fBEAGAIN\fP
+を受信した後、カレントの状態を記録しておくべきである。 これにより、次の \fIdo_use_fd()\fP 呼び出しのときに、以前に停止したところから
+\fBread\fP(2)  または \fBwrite\fP(2)  を継続することができる。
+.PP
+.in +4n
+.EX
+#define MAX_EVENTS 10
+struct epoll_event ev, events[MAX_EVENTS];
+int listen_sock, conn_sock, nfds, epollfd;
+
+/* Code to set up listening socket, \(aqlisten_sock\(aq,
+   (socket(), bind(), listen()) omitted */
+
+epollfd = epoll_create1(0);
+if (epollfd == \-1) {
+    perror("epoll_create1");
+    exit(EXIT_FAILURE);
+}
+
+ev.events = EPOLLIN;
+ev.data.fd = listen_sock;
+if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == \-1) {
+    perror("epoll_ctl: listen_sock");
+    exit(EXIT_FAILURE);
+}
+
+for (;;) {
+    nfds = epoll_wait(epollfd, events, MAX_EVENTS, \-1);
+    if (nfds == \-1) {
+        perror("epoll_wait");
+        exit(EXIT_FAILURE);
+    }
+
+    for (n = 0; n < nfds; ++n) {
+        if (events[n].data.fd == listen_sock) {
+            conn_sock = accept(listen_sock,
+                               (struct sockaddr *) &addr, &addrlen);
+            if (conn_sock == \-1) {
+                perror("accept");
+                exit(EXIT_FAILURE);
+            }
+            setnonblocking(conn_sock);
+            ev.events = EPOLLIN | EPOLLET;
+            ev.data.fd = conn_sock;
+            if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock,
+                        &ev) == \-1) {
+                perror("epoll_ctl: conn_sock");
+                exit(EXIT_FAILURE);
+            }
+        } else {
+            do_use_fd(events[n].data.fd);
+        }
+    }
+}
+.EE
+.in
+.PP
+エッジトリガーインターフェースとして使う場合、性能上の理由により、 一度 (\fBEPOLLIN\fP|\fBEPOLLOUT\fP)  を指定してから
+(\fBEPOLL_CTL_ADD\fP で) ファイルディスクリプターを \fBepoll\fP インターフェースに追加することができる。 これにより、
+\fBepoll_ctl\fP(2)  に \fBEPOLL_CTL_MOD\fP を指定して呼び出すことで \fBEPOLLIN\fP と \fBEPOLLOUT\fP
+の連続的な切り替えが避けられる。
+.SS 質問と解答
+.IP 0. 4
+What is the key used to distinguish the file descriptors registered in an
+interest list?
+.IP
+キーはファイルディスクリプター番号とオープンファイル記述 (open file description) の組である (オープンファイル記述は
+"open file handle" とも 呼ばれ、オープンされたファイルのカーネルの内部表現である)。
+.IP 1.
+1 つの \fBepoll\fP インスタンスに同じファイルディスクリプターを 2 回登録するとどうなるか?
+.IP
+.\" But a file descriptor duplicated by fork(2) can't be added to the
+.\" set, because the [file *, fd] pair is already in the epoll set.
+.\" That is a somewhat ugly inconsistency.  On the one hand, a child process
+.\" cannot add the duplicate file descriptor to the epoll set.  (In every
+.\" other case that I can think of, file descriptors duplicated by fork have
+.\" similar semantics to file descriptors duplicated by dup() and friends.)  On
+.\" the other hand, the very fact that the child has a duplicate of the
+.\" file descriptor means that even if the parent closes its file descriptor,
+.\" then epoll_wait() in the parent will continue to receive notifications for
+.\" that file descriptor because of the duplicated file descriptor in the child.
+.\"
+.\" See http://thread.gmane.org/gmane.linux.kernel/596462/
+.\" "epoll design problems with common fork/exec patterns"
+.\"
+.\" mtk, Feb 2008
+たぶん \fBEEXIST\fP を受け取るだろう。 しかしながら、同じ \fBepoll\fP
+インスタンスに対して複製されたファイルディスクリプターを追加することは可能である (\fBdup\fP(2), \fBdup2\fP(2), \fBfcntl\fP(2)
+\fBF_DUPFD\fP など)。 複製したファイルディスクリプターを異なる \fIevents\fP マスクで登録すれば、イベントをフィルタリングするのに
+この機能は有用な手法である。
+.IP 2.
+2 つの \fBepoll\fP インスタンスが同じファイルディスクリプターを待ち受けることは可能か? もし可能であれば、イベントは両方の \fBepoll\fP
+ファイルディスクリプターに報告されるか?
+.IP
+イベントは両方に報告される。 しかしながら、これを正しく扱うには注意深くプログラミングする必要が あるかもしれない。
+.IP 3.
+\fBepoll\fP ファイルディスクリプター自身は poll/epoll/select が可能か?
+.IP
+可能である。 \fBepoll\fP ファイルディスクリプターに処理待ちのイベントがある場合は、 読み出し可能だと通知されることだろう。
+.IP 4.
+\fBepoll\fP ファイルディスクリプターを自身のファイルディスクリプター集合に 入れようとするとどうなるか?
+.IP
+\fBepoll_ctl\fP(2)  の呼び出しは (\fBEINVAL\fP で) 失敗する。 ただし \fBepoll\fP ファイルディスクリプターを他の
+\fBepoll\fP ファイルディスクリプター集合の内部に追加することは可能である。
+.IP 5.
+\fBepoll\fP ファイルディスクリプターを UNIX ドメインソケットで他のプロセスに送ることは可能か?
+.IP
+Yes, but it does not make sense to do this, since the receiving process
+would not have copies of the file descriptors in the interest list.
+.IP 6.
+Will closing a file descriptor cause it to be removed from all \fBepoll\fP
+interest lists?
+.IP
+Yes, but be aware of the following point.  A file descriptor is a reference
+to an open file description (see \fBopen\fP(2)).  Whenever a file descriptor is
+duplicated via \fBdup\fP(2), \fBdup2\fP(2), \fBfcntl\fP(2)  \fBF_DUPFD\fP, or
+\fBfork\fP(2), a new file descriptor referring to the same open file
+description is created.  An open file description continues to exist until
+all file descriptors referring to it have been closed.
+.IP
+A file descriptor is removed from an interest list only after all the file
+descriptors referring to the underlying open file description have been
+closed.  This means that even after a file descriptor that is part of an
+interest list has been closed, events may be reported for that file
+descriptor if other file descriptors referring to the same underlying file
+description remain open.  To prevent this happening, the file descriptor
+must be explicitly removed from the interest list (using \fBepoll_ctl\fP(2)
+\fBEPOLL_CTL_DEL\fP)  before it is duplicated.  Alternatively, the application
+must ensure that all file descriptors are closed (which may be difficult if
+file descriptors were duplicated behind the scenes by library functions that
+used \fBdup\fP(2)  or \fBfork\fP(2)).
+.IP 7.
+2 つ以上のイベントが \fBepoll_wait\fP(2)  コールの間に発生した場合、それらはまとめて報告されるか、 それとも別々に報告されるか?
+.IP
+まとめて報告されるだろう。
+.IP 8.
+ファイルディスクリプターに対する操作は、 既に集められているがまだ報告されていないイベントに影響するか?
+.IP
+既存のファイルディスクリプターに対して 2 つの操作を行うことができる。 この場合、削除には意味がない。 変更すると、使用可能な I/O
+が再び読み込まれる。
+.IP 9.
+\fBEPOLLET\fP フラグ (エッジトリガー動作) を使っている場合、 \fBEAGAIN\fP を受け取るまで、
+継続してファイルディスクリプターを読み書きする必要があるか?
+.IP
+\fBepoll_wait\fP(2)  からイベントを受け取ることは、 そのファイルディスクリプターが要求された I/O 操作に対して準備済みである、
+ということをユーザーに示すものである。 次の (ブロックしない) read/write で \fBEAGAIN\fP
+を受け取るまではファイルディスクリプターは準備済みであると 考えなければならない。 そのファイルディスクリプターをいつどのように使うかは、
+全くユーザーに任されてる。
+.IP
+パケット指向やトークン指向のファイル (例えば、データグラムソケット、 canonical モードの端末) では、 読み込み用 / 書き込み用の I/O
+空間の末尾を検知する唯一の方法は \fBEAGAIN\fP になるまで read/write を行うことである。
+.IP
+ストリーム指向のファイル (例えば、パイプ、FIFO、ストリームソケット) では、 読み込み用 / 書き込み用の I/O 空間が使い尽くされた状態は、
+対象となるファイルディスクリプターから読み込んだデータ量または 書き込んだデータ量をチェックすることでも検知できる。
+例えば、ある特定の量のデータを読み込むために \fBread\fP(2)  を呼んだときに、 \fBread\fP(2)
+が返したバイト数がそれより少なかった場合、 そのファイルディスクリプターの読み込み用 I/O 空間が 使い尽くされたことが分かる。
+\fBwrite\fP(2)  を使って書き込みをするときも、同じことが言える (監視しているファイルディスクリプターが常にストリーム指向のファイルを
+参照していることを保証できない場合には、後者の手法の使用を避けること)。
+.SS ありがちな落とし穴と回避方法
+.TP 
+\fBo 飢餓 (starvation) (エッジトリガー)\fP
+.PP
+大きな I/O 空間がある場合、 その I/O 空間のデータを全て処理 (drain) しようとすると、
+他のファイルが処理されず、飢餓を発生させることがある (この問題は \fBepoll\fP に固有のものではない)。
+.PP
+この問題の解決法は、準備済み状態のリストを管理して、 関連する data 構造体の中でファイルディスクリプターが 利用可能であるとマークすることである。
+それによって、利用可能なすべてのファイルの中で どのファイルを処理する必要があるかを憶えることができ、 しかも順番に処理 (round robin)
+することができる。 既に利用可能であるファイルディスクリプターに対して それ以後に受け取るイベントを無視することもできる。
+.TP 
+\fBo イベントキャッシュを使っている場合\fP
+.PP
+イベントキャッシュを使っている場合、 または \fBepoll_wait\fP(2)  から返された全てのファイルディスクリプターを格納している場合、
+クローズされたことを動的にマークする (つまり前のイベントの処理によってマークされる) 方法を提供すべきである。 \fBepoll_wait\fP(2)
+から 100 個のイベントを受け取り、 イベント #47 ではある条件でイベント #13 が閉じられると仮定する。 イベント #13
+の構造体を削除しファイルディスクリプターを \fBclose\fP(2)  すると、イベントキャッシュはそのファイルディスクリプターを待つイベントが
+存在するといって、混乱が起きる。
+.PP
+この問題を解決する 1 つの方法は、イベント 47 の処理をしている間に、 ファイルディスクリプター 13 を削除して \fBclose\fP(2)
+するために \fBepoll_ctl\fP(\fBEPOLL_CTL_DEL\fP)  を呼び出し、関連付けられた data 構造体を削除済みとマークして、
+クリーンアップリストにリンクすることである。 バッチ処理の中でファイルディスクリプター 13 についての 他のイベントを見つけた場合、
+そのファイルディスクリプターが以前に削除されたものであると分かるので、 混乱は起きない。
+.SH バージョン
+.\" Its interface should be finalized in Linux kernel 2.5.66.
+\fBepoll\fP API は Linux カーネル 2.5.44 に導入された。 glibc でのサポートはバージョン 2.3.2 で追加された。
+.SH 準拠
+\fBepoll\fP API は Linux 固有である。 他のシステムでも同様の機構が提供されている場合がある。 例えば、FreeBSD の
+\fIkqueue\fP や Solaris の \fI/dev/poll\fP などである。
+.SH 注意
+The set of file descriptors that is being monitored via an epoll file
+descriptor can be viewed via the entry for the epoll file descriptor in the
+process's \fI/proc/[pid]/fdinfo\fP directory.  See \fBproc\fP(5)  for further
+details.
+.PP
+The \fBkcmp\fP(2)  \fBKCMP_EPOLL_TFD\fP operation can be used to test whether a
+file descriptor is present in an epoll instance.
+.SH 関連項目
+\fBepoll_create\fP(2), \fBepoll_create1\fP(2), \fBepoll_ctl\fP(2), \fBepoll_wait\fP(2),
+\fBpoll\fP(2), \fBselect\fP(2)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
+\%https://www.kernel.org/doc/man\-pages/ に書かれている。