1*dba3562dSLionel Sambuc.\" $NetBSD: openpty.3,v 1.17 2012/07/27 21:33:46 christos Exp $ 20c3983b2SBen Gras.\" 30c3983b2SBen Gras.\" Copyright (c) 1995 40c3983b2SBen Gras.\" The Regents of the University of California. All rights reserved. 50c3983b2SBen Gras.\" 60c3983b2SBen Gras.\" This code is derived from software developed by the Computer Systems 70c3983b2SBen Gras.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 80c3983b2SBen Gras.\" BG 91-66 and contributed to Berkeley. 90c3983b2SBen Gras.\" 100c3983b2SBen Gras.\" Redistribution and use in source and binary forms, with or without 110c3983b2SBen Gras.\" modification, are permitted provided that the following conditions 120c3983b2SBen Gras.\" are met: 130c3983b2SBen Gras.\" 1. Redistributions of source code must retain the above copyright 140c3983b2SBen Gras.\" notice, this list of conditions and the following disclaimer. 150c3983b2SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 160c3983b2SBen Gras.\" notice, this list of conditions and the following disclaimer in the 170c3983b2SBen Gras.\" documentation and/or other materials provided with the distribution. 180c3983b2SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 190c3983b2SBen Gras.\" may be used to endorse or promote products derived from this software 200c3983b2SBen Gras.\" without specific prior written permission. 210c3983b2SBen Gras.\" 220c3983b2SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 230c3983b2SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 240c3983b2SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 250c3983b2SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 260c3983b2SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 270c3983b2SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 280c3983b2SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 290c3983b2SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 300c3983b2SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 310c3983b2SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 320c3983b2SBen Gras.\" SUCH DAMAGE. 330c3983b2SBen Gras.\" 34*dba3562dSLionel Sambuc.Dd July 27, 2012 350c3983b2SBen Gras.Dt OPENPTY 3 360c3983b2SBen Gras.Os 370c3983b2SBen Gras.Sh NAME 380c3983b2SBen Gras.Nm openpty , 390c3983b2SBen Gras.Nm login_tty , 400c3983b2SBen Gras.Nm forkpty 410c3983b2SBen Gras.Nd tty utility functions 420c3983b2SBen Gras.Sh LIBRARY 430c3983b2SBen Gras.Lb libutil 440c3983b2SBen Gras.Sh SYNOPSIS 450c3983b2SBen Gras.In util.h 460c3983b2SBen Gras.Ft int 470c3983b2SBen Gras.Fn openpty "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp" 480c3983b2SBen Gras.Ft int 490c3983b2SBen Gras.Fn login_tty "int fd" 500c3983b2SBen Gras.Ft pid_t 510c3983b2SBen Gras.Fn forkpty "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp" 520c3983b2SBen Gras.Sh DESCRIPTION 530c3983b2SBen GrasThe 540c3983b2SBen Gras.Fn openpty , 550c3983b2SBen Gras.Fn login_tty , 560c3983b2SBen Grasand 570c3983b2SBen Gras.Fn forkpty 580c3983b2SBen Grasfunctions perform manipulations on ttys and pseudo-ttys. 590c3983b2SBen Gras.Pp 600c3983b2SBen GrasThe 610c3983b2SBen Gras.Fn openpty 620c3983b2SBen Grasfunction finds an available pseudo-tty and returns file descriptors 630c3983b2SBen Grasfor the master and slave in 640c3983b2SBen Gras.Fa amaster 650c3983b2SBen Grasand 660c3983b2SBen Gras.Fa aslave . 670c3983b2SBen GrasIf 680c3983b2SBen Gras.Fa name 690c3983b2SBen Grasis non-null, the filename of the slave is returned in 700c3983b2SBen Gras.Fa name . 71*dba3562dSLionel SambucThe length of 72*dba3562dSLionel Sambuc.Fa name 73*dba3562dSLionel Sambucis limited to 74*dba3562dSLionel Sambuc.Dv PATH_MAX 75*dba3562dSLionel Sambucas any other regular path name, so a buffer of this size should be used. 76*dba3562dSLionel Sambuc.\" .Dv 16 77*dba3562dSLionel Sambuc.\" characters in the current 78*dba3562dSLionel Sambuc.\" .Xr ptm 4 79*dba3562dSLionel Sambuc.\" device driver (including the terminating 80*dba3562dSLionel Sambuc.\" .Dv NUL ) 81*dba3562dSLionel Sambuc.\" which limits the maximum to 82*dba3562dSLionel Sambuc.\" .Dv 100,000 83*dba3562dSLionel Sambuc.\" ptys. 840c3983b2SBen GrasIf 850c3983b2SBen Gras.Fa termp 860c3983b2SBen Grasis non-null, the terminal parameters of the slave will be set to the 870c3983b2SBen Grasvalues in 880c3983b2SBen Gras.Fa termp . 890c3983b2SBen GrasIf 900c3983b2SBen Gras.Fa winp 910c3983b2SBen Grasis non-null, the window size of the slave will be set to the values in 920c3983b2SBen Gras.Fa winp . 930c3983b2SBen Gras.Pp 940c3983b2SBen GrasThe 950c3983b2SBen Gras.Fn login_tty 960c3983b2SBen Grasfunction prepares for a login on the tty 970c3983b2SBen Gras.Fa fd 980c3983b2SBen Gras(which may be a real tty device, or the slave of a pseudo-tty as 990c3983b2SBen Grasreturned by 1000c3983b2SBen Gras.Fn openpty ) 1010c3983b2SBen Grasby creating a new session, making 1020c3983b2SBen Gras.Fa fd 1030c3983b2SBen Grasthe controlling terminal for the current process, setting 1040c3983b2SBen Gras.Fa fd 1050c3983b2SBen Grasto be the standard input, output, and error streams of the current 1060c3983b2SBen Grasprocess, and closing 1070c3983b2SBen Gras.Fa fd . 1080c3983b2SBen Gras.Pp 1090c3983b2SBen GrasThe 1100c3983b2SBen Gras.Fn forkpty 1110c3983b2SBen Grasfunction combines 1120c3983b2SBen Gras.Fn openpty , 1130c3983b2SBen Gras.Fn fork , 1140c3983b2SBen Grasand 1150c3983b2SBen Gras.Fn login_tty 1160c3983b2SBen Grasto create a new process operating in a pseudo-tty. 1170c3983b2SBen GrasThe file descriptor of the master side of the pseudo-tty is returned 1180c3983b2SBen Gras(to the parent process only) in 1190c3983b2SBen Gras.Fa amaster . 1200c3983b2SBen GrasThe filename of the slave is returned (to both the parent and child 1210c3983b2SBen Grasprocesses) in 1220c3983b2SBen Gras.Fa name 1230c3983b2SBen Grasif 1240c3983b2SBen Gras.Fa name 1250c3983b2SBen Grasis non-null. 1260c3983b2SBen GrasThe 1270c3983b2SBen Gras.Fa termp 1280c3983b2SBen Grasand 1290c3983b2SBen Gras.Fa winp 1300c3983b2SBen Grasparameters, if non-null, will determine the terminal attributes and 1310c3983b2SBen Graswindow size of the slave side of the pseudo-tty. 1320c3983b2SBen Gras.Sh RETURN VALUES 1330c3983b2SBen GrasIf a call to 1340c3983b2SBen Gras.Fn openpty , 1350c3983b2SBen Gras.Fn login_tty , 1360c3983b2SBen Grasor 1370c3983b2SBen Gras.Fn forkpty 1380c3983b2SBen Grasis not successful, -1 is returned and 1390c3983b2SBen Gras.Va errno 1400c3983b2SBen Grasis set to indicate the error. 1410c3983b2SBen GrasOtherwise, 1420c3983b2SBen Gras.Fn openpty , 1430c3983b2SBen Gras.Fn login_tty , 1440c3983b2SBen Grasand the child process of 1450c3983b2SBen Gras.Fn forkpty 1460c3983b2SBen Grasreturn 0, and the parent process of 1470c3983b2SBen Gras.Fn forkpty 1480c3983b2SBen Grasreturns the process ID of the child process. 1490c3983b2SBen Gras.Sh FILES 1500c3983b2SBen Gras.Bl -tag -width /dev/[pt]ty[p-zP-T][0-9a-zA-Z] -compact 1510c3983b2SBen Gras.It Pa /dev/[pt]ty[p-zP-T][0-9a-zA-Z] 1520c3983b2SBen Gras.El 1530c3983b2SBen Gras.Sh ERRORS 1540c3983b2SBen Gras.Fn openpty 1550c3983b2SBen Graswill fail if: 1560c3983b2SBen Gras.Bl -tag -width Er 1570c3983b2SBen Gras.It Bq Er ENOENT 1580c3983b2SBen GrasThere are no available ttys. 1590c3983b2SBen Gras.It Bq Er EPERM 1600c3983b2SBen GrasThe caller was not the superuser and the 1610c3983b2SBen Gras.Xr ptm 4 1620c3983b2SBen Grasdevice is missing or not configured. 1630c3983b2SBen Gras.El 1640c3983b2SBen Gras.Pp 1650c3983b2SBen Gras.Fn login_tty 1660c3983b2SBen Graswill fail if 1670c3983b2SBen Gras.Fn ioctl 1680c3983b2SBen Grasfails to set 1690c3983b2SBen Gras.Fa fd 1700c3983b2SBen Grasto the controlling terminal of the current process. 1710c3983b2SBen Gras.Fn forkpty 1720c3983b2SBen Graswill fail if either 1730c3983b2SBen Gras.Fn openpty 1740c3983b2SBen Grasor 1750c3983b2SBen Gras.Fn fork 1760c3983b2SBen Grasfails. 1770c3983b2SBen Gras.Sh SEE ALSO 1780c3983b2SBen Gras.Xr fork 2 179