man-pages/man3/openpty.3

173 lines
4.6 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright (c) OpenBSD Group
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" Converted into a manpage again by Martin Schulze <joey@infodrom.org>
.\"
.\" Added -lutil remark, 030718
.\"
2007-05-18 09:55:10 +00:00
.TH OPENPTY 3 2003-07-18 "GNU" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
openpty, login_tty, forkpty \- tty utility functions
.SH SYNOPSIS
2007-04-03 15:32:52 +00:00
.nf
2004-11-03 13:51:07 +00:00
.B #include <pty.h>
.sp
.BI "int openpty(int *" amaster ", int *" aslave ", char *" name ,
2007-04-03 15:32:52 +00:00
.BI " struct termios *" termp ", struct winsize *" winp );
2004-11-03 13:51:07 +00:00
.sp
.BI "pid_t forkpty(int *" amaster ", char *" name ", struct termios *" termp ,
2007-04-03 15:32:52 +00:00
.BI " struct winsize *" winp );
2004-11-03 13:51:07 +00:00
.sp
2007-06-13 22:20:51 +00:00
.B #include <utmp.h>
.sp
.BI "int login_tty(int " fd );
.sp
Link with \fI\-lutil\fP.
2007-04-03 15:32:52 +00:00
.fi
2004-11-03 13:51:07 +00:00
.SH DESCRIPTION
The
.BR openpty ()
2005-07-18 17:10:04 +00:00
function finds an available pseudo-terminal and returns file descriptors
2004-11-03 13:51:07 +00:00
for the master and slave in
.I amaster
and
.IR aslave .
If
.I name
is not NULL, the filename of the slave is returned in
.IR name .
If
.I termp
is not NULL, the terminal parameters of the slave will be set to the
values in
.IR termp .
If
.I winp
is not NULL, the window size of the slave will be set to the values in
.IR winp .
The
.BR login_tty ()
2004-11-03 13:51:07 +00:00
function prepares for a login on the tty
.I fd
2005-07-18 17:10:04 +00:00
(which may be a real tty device, or the slave of a pseudo-terminal as
2004-11-03 13:51:07 +00:00
returned by
.BR openpty ())
2004-11-03 13:51:07 +00:00
by creating a new session, making
.I fd
2007-12-27 16:06:35 +00:00
the controlling terminal for the calling process, setting
2004-11-03 13:51:07 +00:00
.I fd
to be the standard input, output, and error streams of the current
process, and closing
.IR fd .
The
.BR forkpty ()
2004-11-03 13:51:07 +00:00
function combines
.BR openpty (),
.BR fork (2),
2004-11-03 13:51:07 +00:00
and
.BR login_tty ()
to create a new process operating in a pseudo-terminal.
The file
2005-07-18 17:10:04 +00:00
descriptor of the master side of the pseudo-terminal is returned in
2004-11-03 13:51:07 +00:00
.IR amaster ,
and the filename of the slave in
.I name
if it is not NULL.
The
2004-11-03 13:51:07 +00:00
.I termp
and
.I winp
arguments, if not NULL,
2004-11-03 13:51:07 +00:00
will determine the terminal attributes and window size of the slave
2005-07-18 17:10:04 +00:00
side of the pseudo-terminal.
2007-05-16 05:00:31 +00:00
.SH "RETURN VALUE"
2004-11-03 13:51:07 +00:00
If a call to
.BR openpty (),
.BR login_tty (),
2004-11-03 13:51:07 +00:00
or
.BR forkpty ()
2005-06-15 14:10:23 +00:00
is not successful, \-1 is returned and
2004-11-03 13:51:07 +00:00
.I errno
is set to indicate the error.
Otherwise,
.BR openpty (),
.BR login_tty (),
2004-11-03 13:51:07 +00:00
and the child process of
.BR forkpty ()
2004-11-03 13:51:07 +00:00
return 0, and the parent process of
.BR forkpty ()
2004-11-03 13:51:07 +00:00
returns the process ID of the child process.
.SH ERRORS
.BR openpty ()
2004-11-03 13:51:07 +00:00
will fail if:
.TP
.B ENOENT
There are no available ttys.
.LP
2007-05-21 22:02:11 +00:00
.BR login_tty ()
2004-11-03 13:51:07 +00:00
will fail if
.BR ioctl (2)
2004-11-03 13:51:07 +00:00
fails to set
.I fd
2007-12-27 16:06:35 +00:00
to the controlling terminal of the calling process.
2004-11-03 13:51:07 +00:00
.LP
.BR forkpty ()
2004-11-03 13:51:07 +00:00
will fail if either
.BR openpty ()
2004-11-03 13:51:07 +00:00
or
.BR fork (2)
2004-11-03 13:51:07 +00:00
fails.
.SH "CONFORMING TO"
These are BSD functions, present in libc5 and glibc2.
.SH NOTES
.\" These functions are included in libutil, hence you'll need to add
.\" .B \-lutil
.\" to your compiler command line.
2007-06-21 22:55:04 +00:00
.\"
In versions of glibc before 2.0.92,
.BR openpty ()
returns file descriptors for a BSD pseudo-terminal pair;
since glibc 2.0.92,
2006-01-17 20:13:03 +00:00
it first attempts to open a Unix 98 pseudo-terminal pair,
and falls back to opening a BSD pseudo-terminal pair if that fails.
2004-11-03 13:51:07 +00:00
.SH BUGS
Nobody knows how much space should be reserved for
.IR name .
So, calling
.BR openpty ()
2004-11-03 13:51:07 +00:00
or
.BR forkpty ()
2004-11-03 13:51:07 +00:00
with non-NULL
.I name
may not be secure.
.SH "SEE ALSO"
2005-10-10 13:14:12 +00:00
.BR fork (2),
2008-04-28 20:25:11 +00:00
.BR ttyname (3),
2005-10-10 13:14:12 +00:00
.BR pty (7)