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
|
|
|
|
.\"
|
2010-06-13 01:47:33 +00:00
|
|
|
.TH OPENPTY 3 2010-06-13 "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
|
2007-04-12 22:42:49 +00:00
|
|
|
.BI "int openpty(int *" amaster ", int *" aslave ", char *" name ,
|
2010-02-05 21:05:30 +00:00
|
|
|
.BI " const struct termios *" termp ,
|
|
|
|
.BI " const struct winsize *" winp );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
2010-02-05 21:05:30 +00:00
|
|
|
.BI "pid_t forkpty(int *" amaster ", char *" name ,
|
|
|
|
.BI " const struct termios *" termp ,
|
|
|
|
.BI " const 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
|
2007-05-21 09:49:04 +00:00
|
|
|
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
|
2005-10-19 07:07:02 +00:00
|
|
|
.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
|
2005-10-19 07:07:02 +00:00
|
|
|
.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
|
2005-10-19 07:07:02 +00:00
|
|
|
.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
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR forkpty ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function combines
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR openpty (),
|
2007-05-12 00:30:29 +00:00
|
|
|
.BR fork (2),
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR login_tty ()
|
2007-04-12 22:42:49 +00:00
|
|
|
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
|
2007-04-12 22:42:49 +00:00
|
|
|
if it is not NULL.
|
|
|
|
The
|
2004-11-03 13:51:07 +00:00
|
|
|
.I termp
|
|
|
|
and
|
|
|
|
.I winp
|
2008-07-10 20:53:08 +00:00
|
|
|
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
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR openpty (),
|
|
|
|
.BR login_tty (),
|
2004-11-03 13:51:07 +00:00
|
|
|
or
|
2005-10-19 07:07:02 +00:00
|
|
|
.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
|
2007-04-12 22:42:49 +00:00
|
|
|
is set to indicate the error.
|
|
|
|
Otherwise,
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR openpty (),
|
|
|
|
.BR login_tty (),
|
2004-11-03 13:51:07 +00:00
|
|
|
and the child process of
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR forkpty ()
|
2004-11-03 13:51:07 +00:00
|
|
|
return 0, and the parent process of
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR forkpty ()
|
2004-11-03 13:51:07 +00:00
|
|
|
returns the process ID of the child process.
|
|
|
|
.SH ERRORS
|
2005-10-19 07:07:02 +00:00
|
|
|
.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
|
2007-05-12 00:30:29 +00:00
|
|
|
.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
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR forkpty ()
|
2004-11-03 13:51:07 +00:00
|
|
|
will fail if either
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR openpty ()
|
2004-11-03 13:51:07 +00:00
|
|
|
or
|
2007-05-12 00:30:29 +00:00
|
|
|
.BR fork (2)
|
2004-11-03 13:51:07 +00:00
|
|
|
fails.
|
2007-05-19 04:30:20 +00:00
|
|
|
.SH "CONFORMING TO"
|
|
|
|
These are BSD functions, present in libc5 and glibc2.
|
2010-06-13 01:47:33 +00:00
|
|
|
They are not standardized in POSIX.
|
2006-01-16 22:07:42 +00:00
|
|
|
.SH NOTES
|
2010-06-13 01:45:46 +00:00
|
|
|
The
|
|
|
|
.B const
|
|
|
|
modifiers were added to the structure pointer arguments of
|
|
|
|
.BR openpty ()
|
|
|
|
and
|
|
|
|
.BR forkpty ()
|
|
|
|
in glibc 2.8.
|
|
|
|
|
2006-01-16 22:07:42 +00:00
|
|
|
In versions of glibc before 2.0.92,
|
|
|
|
.BR openpty ()
|
2007-04-12 22:42:49 +00:00
|
|
|
returns file descriptors for a BSD pseudo-terminal pair;
|
|
|
|
since glibc 2.0.92,
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
it first attempts to open a UNIX 98 pseudo-terminal pair,
|
2006-01-17 20:13:03 +00:00
|
|
|
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
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR openpty ()
|
2004-11-03 13:51:07 +00:00
|
|
|
or
|
2005-10-19 07:07:02 +00:00
|
|
|
.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)
|