openptyのヘルプ・マニュアル
日本語 英語
openpty --help
man openpty
OPENPTY(3) Linux Programmer’s Manual OPENPTY(3)
名前
openpty, login_tty, forkpty - 端末 (tty) ユーティリティ関数
書式
#include
int openpty(int *amaster, int *aslave, char *name,
struct termios *termp, struct winsize *winp);
pid_t forkpty(int *amaster, char *name, struct termios *termp,
struct winsize *winp);
#include
int login_tty(int fd);
-lutil でリンクする。
説明
openpty() 関数は、使用可能な疑似端末 (pseudo-terminal) を見つけて、マス
タとスレーブのファイル・ディスクリプタを amaster と aslave に入れて返す
。 name が NULL でない場合、スレーブのファイル名が name に返される。
termp が NULL でない場合、スレーブの端末パラメータは termp の値に設定さ
れ る。 winp が NULL でない場合、スレーブのウインドウサイズは winp に設
定される。
login_tty() 関数は、端末 fd にログインする準備をする (fd は実際の端末デ
バ イスでも、 openpty() で返される疑似端末のスレーブでもよい)。具体的に
は、新しいセッションを作成し、 fd を呼び出し元のプロセスの制御端末と し
、 呼び出し元の標準入力・標準出力・標準エラーのストリームを fd に設定し
た後、 fd をクローズする。
forkpty() 関数は openpty(), fork(2), login_tty() を組み合わせ、疑似端末
を 操作する新しいプロセスを生成する。疑似端末のマスタ側のファイル・ディ
スクリプタは amaster に返され、 name が NULL でない場合には、スレーブの
フ ァイル名が name に返される。 termp と winp 引き数は、NULL でなければ
、疑似端末のスレーブ側の端末属性とウインドウサイズを決定する。
返り値
openpty(), login_tty(), forkpty() の呼び出しが成功しなかった場合 、 -1
が 返 さ れ て 、 errno はエラーを示す値に設定される。成功した場合、
openpty(), login_tty() および forkpty() の子プロセスは 0 を返 し 、
forkpty() の親プロセスは子プロセスのプロセス ID を返す。
エラー
以下の場合に openpty() は失敗する:
ENOENT 使用可能な端末がない。
ioctl(2) が fd を呼び出し元のプロセスの制御端末に設定するのに失敗した場
合、 login_tty() は失敗する。
openpty() または fork(2) のどちらかが失敗した場合、 forkpty() は失敗 す
る。
準拠
これらは BSD の関数であり、libc5 と glibc2 に存在する。
注意
2.0.92 より前のバージョンの glibc では、 openpty() は BSD 疑似端末ペア
のファイル・ディスクリプタを返す。 2.0.92 以降の glibc では、 openpty()
は ま ず Unix 98 疑似端末ペアをオープンしようとし、それに失敗した場合に
BSD 疑似端末ペアのオープンへと移行する。
バグ
誰も name に対してどのくらい大きさを予約しておけばいいか分からない。 し
たがって、NULL でない name を引き数として openpty() や forkpty() を呼び
出すのは安全であるとは言えない。
関連項目
fork(2), ttyname(3), pty(7)
GNU 2003-07-18 OPENPTY(3)
OPENPTY(3) Linux Programmer’s Manual OPENPTY(3)
NAME
openpty, login_tty, forkpty - tty utility functions
SYNOPSIS
#include
int openpty(int *amaster, int *aslave, char *name,
struct termios *termp, struct winsize *winp);
pid_t forkpty(int *amaster, char *name, struct termios *termp,
struct winsize *winp);
#include
int login_tty(int fd);
Link with -lutil.
DESCRIPTION
The openpty() function finds an available pseudo-terminal and returns
file descriptors for the master and slave in amaster and aslave. If
name is not NULL, the filename of the slave is returned in name. If
termp is not NULL, the terminal parameters of the slave will be set to
the values in termp. If winp is not NULL, the window size of the slave
will be set to the values in winp.
The login_tty() function prepares for a login on the tty fd (which may
be a real tty device, or the slave of a pseudo-terminal as returned by
openpty()) by creating a new session, making fd the controlling termi-
nal for the calling process, setting fd to be the standard input, out-
put, and error streams of the current process, and closing fd.
The forkpty() function combines openpty(), fork(2), and login_tty() to
create a new process operating in a pseudo-terminal. The file descrip-
tor of the master side of the pseudo-terminal is returned in amaster,
and the filename of the slave in name if it is not NULL. The termp and
winp arguments, if not NULL, will determine the terminal attributes and
window size of the slave side of the pseudo-terminal.
RETURN VALUE
If a call to openpty(), login_tty(), or forkpty() is not successful, -1
is returned and errno is set to indicate the error. Otherwise,
openpty(), login_tty(), and the child process of forkpty() return 0,
and the parent process of forkpty() returns the process ID of the child
process.
ERRORS
openpty() will fail if:
ENOENT There are no available ttys.
login_tty() will fail if ioctl(2) fails to set fd to the controlling
terminal of the calling process.
forkpty() will fail if either openpty() or fork(2) fails.
CONFORMING TO
These are BSD functions, present in libc5 and glibc2.
NOTES
In versions of glibc before 2.0.92, openpty() returns file descriptors
for a BSD pseudo-terminal pair; since glibc 2.0.92, it first attempts
to open a Unix 98 pseudo-terminal pair, and falls back to opening a BSD
pseudo-terminal pair if that fails.
BUGS
Nobody knows how much space should be reserved for name. So, calling
openpty() or forkpty() with non-NULL name may not be secure.
SEE ALSO
fork(2), ttyname(3), pty(7)
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 2003-07-18 OPENPTY(3)