[BACK]Return to openpty.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libutil

File: [cvs.NetBSD.org] / src / lib / libutil / openpty.3 (download)

Revision 1.14, Fri Nov 28 07:17:17 2008 UTC (15 years, 4 months ago) by dholland
Branch: MAIN
CVS Tags: yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-premerge-20091211, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, christos-time_t-base, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2
Branch point for: yamt-pagecache, christos-time_t
Changes since 1.13: +10 -6 lines

Clarify that the "amaster" argument of forkpty() is only defined upon
return in the parent process, but the tty name is available to both
the parent and child. Bump date.

.\"	$NetBSD: openpty.3,v 1.14 2008/11/28 07:17:17 dholland Exp $
.\"
.\" 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.
.\" 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.
.\"
.Dd November 28, 2008
.Dt OPENPTY 3
.Os
.Sh NAME
.Nm openpty ,
.Nm login_tty ,
.Nm forkpty
.Nd tty utility functions
.Sh LIBRARY
.Lb libutil
.Sh SYNOPSIS
.In util.h
.Ft int
.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
.Fn forkpty
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
to create a new process operating in a pseudo-tty.
The file descriptor of the master side of the pseudo-tty is returned
(to the parent process only) in
.Fa amaster .
The filename of the slave is returned (to both the parent and child
processes) in
.Fa name
if
.Fa name
is non-null.
The
.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
.Fn forkpty
is not successful, -1 is returned and
.Va errno
is set to indicate the error.
Otherwise,
.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.
.Sh FILES
.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]
.El
.Sh ERRORS
.Fn openpty
will fail if:
.Bl -tag -width Er
.It Bq Er ENOENT
There are no available ttys.
.It Bq Er EPERM
The caller was not the superuser and the
.Xr ptm 4
device is missing or not configured.
.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.
.Sh SEE ALSO
.Xr fork 2