2004-06-18 06:42:57 +04:00
|
|
|
.\" $NetBSD: openpty.3,v 1.13 2004/06/18 02:42:57 christos Exp $
|
1998-01-09 07:11:49 +03:00
|
|
|
.\"
|
1996-05-16 01:42:23 +04:00
|
|
|
.\" Copyright (c) 1995
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software developed by the Computer Systems
|
|
|
|
.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
|
|
|
|
.\" BG 91-66 and contributed to Berkeley.
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
2003-08-07 20:42:00 +04:00
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
1996-05-16 01:42:23 +04:00
|
|
|
.\" 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.
|
|
|
|
.\"
|
2004-06-18 06:42:57 +04:00
|
|
|
.Dd June 17, 2004
|
1996-05-16 01:42:23 +04:00
|
|
|
.Dt OPENPTY 3
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm openpty ,
|
|
|
|
.Nm login_tty ,
|
|
|
|
.Nm forkpty
|
|
|
|
.Nd tty utility functions
|
1998-02-05 21:45:17 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libutil
|
1996-05-16 01:42:23 +04:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In util.h
|
1996-11-03 17:27:54 +03:00
|
|
|
.Ft int
|
1996-05-16 01:42:23 +04:00
|
|
|
.Fn openpty "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp"
|
|
|
|
.Ft int
|
|
|
|
.Fn login_tty "int fd"
|
|
|
|
.Ft pid_t
|
|
|
|
.Fn forkpty "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn openpty ,
|
|
|
|
.Fn login_tty ,
|
|
|
|
and
|
1996-11-03 17:27:54 +03:00
|
|
|
.Fn forkpty
|
1996-05-16 01:42:23 +04:00
|
|
|
functions perform manipulations on ttys and pseudo-ttys.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn openpty
|
|
|
|
function finds an available pseudo-tty and returns file descriptors
|
|
|
|
for the master and slave in
|
|
|
|
.Fa amaster
|
|
|
|
and
|
|
|
|
.Fa aslave .
|
|
|
|
If
|
|
|
|
.Fa name
|
|
|
|
is non-null, the filename of the slave is returned in
|
|
|
|
.Fa name .
|
|
|
|
If
|
|
|
|
.Fa termp
|
|
|
|
is non-null, the terminal parameters of the slave will be set to the
|
|
|
|
values in
|
|
|
|
.Fa termp .
|
|
|
|
If
|
|
|
|
.Fa winp
|
|
|
|
is non-null, the window size of the slave will be set to the values in
|
|
|
|
.Fa winp .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn login_tty
|
|
|
|
function prepares for a login on the tty
|
|
|
|
.Fa fd
|
|
|
|
(which may be a real tty device, or the slave of a pseudo-tty as
|
|
|
|
returned by
|
|
|
|
.Fn openpty )
|
|
|
|
by creating a new session, making
|
|
|
|
.Fa fd
|
|
|
|
the controlling terminal for the current process, setting
|
|
|
|
.Fa fd
|
|
|
|
to be the standard input, output, and error streams of the current
|
|
|
|
process, and closing
|
|
|
|
.Fa fd .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn forkpty
|
|
|
|
function combines
|
|
|
|
.Fn openpty ,
|
|
|
|
.Fn fork ,
|
|
|
|
and
|
|
|
|
.Fn login_tty
|
2003-05-06 11:38:19 +04:00
|
|
|
to create a new process operating in a pseudo-tty.
|
2002-10-01 23:36:30 +04:00
|
|
|
The file descriptor of the master side of the pseudo-tty is returned in
|
1996-05-16 01:42:23 +04:00
|
|
|
.Fa amaster ,
|
|
|
|
and the filename of the slave in
|
|
|
|
.Fa name
|
2002-10-01 23:36:30 +04:00
|
|
|
if it is non-null.
|
|
|
|
The
|
1996-05-16 01:42:23 +04:00
|
|
|
.Fa termp
|
|
|
|
and
|
|
|
|
.Fa winp
|
|
|
|
parameters, if non-null, will determine the terminal attributes and
|
|
|
|
window size of the slave side of the pseudo-tty.
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
If a call to
|
|
|
|
.Fn openpty ,
|
|
|
|
.Fn login_tty ,
|
|
|
|
or
|
1996-11-03 17:27:54 +03:00
|
|
|
.Fn forkpty
|
1996-05-16 01:42:23 +04:00
|
|
|
is not successful, -1 is returned and
|
|
|
|
.Va errno
|
2002-10-01 23:36:30 +04:00
|
|
|
is set to indicate the error.
|
|
|
|
Otherwise,
|
1996-11-03 17:27:54 +03:00
|
|
|
.Fn openpty ,
|
|
|
|
.Fn login_tty ,
|
|
|
|
and the child process of
|
|
|
|
.Fn forkpty
|
|
|
|
return 0, and the parent process of
|
|
|
|
.Fn forkpty
|
|
|
|
returns the process ID of the child process.
|
2002-02-20 14:34:14 +03:00
|
|
|
.Sh FILES
|
2002-05-30 05:42:58 +04:00
|
|
|
.Bl -tag -width /dev/[pt]ty[p-zP-T][0-9a-zA-Z] -compact
|
|
|
|
.It Pa /dev/[pt]ty[p-zP-T][0-9a-zA-Z]
|
2002-02-20 14:34:14 +03:00
|
|
|
.El
|
1996-05-16 01:42:23 +04:00
|
|
|
.Sh ERRORS
|
|
|
|
.Fn openpty
|
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er ENOENT
|
|
|
|
There are no available ttys.
|
2004-06-18 06:42:57 +04:00
|
|
|
.It Bq Er EPERM
|
|
|
|
The caller was not the superuser and the
|
|
|
|
.Xr ptm 4
|
|
|
|
device is missing or not configured.
|
1996-05-16 01:42:23 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
.Fn login_tty
|
|
|
|
will fail if
|
|
|
|
.Fn ioctl
|
|
|
|
fails to set
|
|
|
|
.Fa fd
|
|
|
|
to the controlling terminal of the current process.
|
|
|
|
.Fn forkpty
|
|
|
|
will fail if either
|
|
|
|
.Fn openpty
|
|
|
|
or
|
|
|
|
.Fn fork
|
|
|
|
fails.
|
1996-11-03 17:27:54 +03:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr fork 2
|