xref: /f-stack/tools/libutil/pty.3 (revision 22ce4aff)
11eaf0ac3Slogwang.\"
21eaf0ac3Slogwang.\" Copyright (c) 1996 Joerg Wunsch
31eaf0ac3Slogwang.\"
41eaf0ac3Slogwang.\" All rights reserved.
51eaf0ac3Slogwang.\"
61eaf0ac3Slogwang.\" Redistribution and use in source and binary forms, with or without
71eaf0ac3Slogwang.\" modification, are permitted provided that the following conditions
81eaf0ac3Slogwang.\" are met:
91eaf0ac3Slogwang.\" 1. Redistributions of source code must retain the above copyright
101eaf0ac3Slogwang.\"    notice, this list of conditions and the following disclaimer.
111eaf0ac3Slogwang.\" 2. Redistributions in binary form must reproduce the above copyright
121eaf0ac3Slogwang.\"    notice, this list of conditions and the following disclaimer in the
131eaf0ac3Slogwang.\"    documentation and/or other materials provided with the distribution.
141eaf0ac3Slogwang.\"
151eaf0ac3Slogwang.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
161eaf0ac3Slogwang.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171eaf0ac3Slogwang.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181eaf0ac3Slogwang.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
191eaf0ac3Slogwang.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201eaf0ac3Slogwang.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211eaf0ac3Slogwang.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221eaf0ac3Slogwang.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231eaf0ac3Slogwang.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241eaf0ac3Slogwang.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251eaf0ac3Slogwang.\"
261eaf0ac3Slogwang.\" $FreeBSD$
271eaf0ac3Slogwang.\" "
28*22ce4affSfengbojiang.Dd June 2, 2018
291eaf0ac3Slogwang.Dt PTY 3
301eaf0ac3Slogwang.Os
311eaf0ac3Slogwang.Sh NAME
321eaf0ac3Slogwang.Nm openpty ,
331eaf0ac3Slogwang.Nm forkpty
341eaf0ac3Slogwang.Nd auxiliary functions to obtain a pseudo-terminal
351eaf0ac3Slogwang.Sh LIBRARY
361eaf0ac3Slogwang.Lb libutil
371eaf0ac3Slogwang.Sh SYNOPSIS
381eaf0ac3Slogwang.In sys/types.h
391eaf0ac3Slogwang.In sys/ioctl.h
401eaf0ac3Slogwang.In termios.h
411eaf0ac3Slogwang.In libutil.h
421eaf0ac3Slogwang.Ft int
431eaf0ac3Slogwang.Fn openpty "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp"
441eaf0ac3Slogwang.Ft int
451eaf0ac3Slogwang.Fn forkpty "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp"
461eaf0ac3Slogwang.Sh DESCRIPTION
471eaf0ac3SlogwangThe function
481eaf0ac3Slogwang.Fn openpty
491eaf0ac3Slogwangattempts to obtain the next available pseudo-terminal from the system (see
501eaf0ac3Slogwang.Xr pty 4 ) .
511eaf0ac3SlogwangIf it successfully finds one, it subsequently changes the
521eaf0ac3Slogwangownership of the slave device to the real UID of the current process,
531eaf0ac3Slogwangthe group membership to the group
541eaf0ac3Slogwang.Dq tty
551eaf0ac3Slogwang(if such a group exists in the system), the access permissions for
561eaf0ac3Slogwangreading and writing by the owner, and for writing by the group, and
571eaf0ac3Slogwanginvalidates any current use of the line by calling
581eaf0ac3Slogwang.Xr revoke 2 .
591eaf0ac3Slogwang.Pp
601eaf0ac3SlogwangIf the argument
611eaf0ac3Slogwang.Fa name
621eaf0ac3Slogwangis not
631eaf0ac3Slogwang.Dv NULL ,
641eaf0ac3Slogwang.Fn openpty
651eaf0ac3Slogwangcopies the pathname of the slave pty to this area.
661eaf0ac3SlogwangThe caller is
671eaf0ac3Slogwangresponsible for allocating the required space in this array.
681eaf0ac3Slogwang.Pp
691eaf0ac3SlogwangIf the arguments
701eaf0ac3Slogwang.Fa termp
711eaf0ac3Slogwangor
721eaf0ac3Slogwang.Fa winp
731eaf0ac3Slogwangare not
741eaf0ac3Slogwang.Dv NULL ,
751eaf0ac3Slogwang.Fn openpty
761eaf0ac3Slogwanginitializes the termios and window size settings from the structures
771eaf0ac3Slogwangthese arguments point to, respectively.
781eaf0ac3Slogwang.Pp
791eaf0ac3SlogwangUpon return, the open file descriptors for the master and slave side
801eaf0ac3Slogwangof the pty are returned in the locations pointed to by
811eaf0ac3Slogwang.Fa amaster
821eaf0ac3Slogwangand
831eaf0ac3Slogwang.Fa aslave ,
841eaf0ac3Slogwangrespectively.
851eaf0ac3Slogwang.Pp
861eaf0ac3SlogwangThe
871eaf0ac3Slogwang.Fn forkpty
881eaf0ac3Slogwangfunction first calls
891eaf0ac3Slogwang.Fn openpty
901eaf0ac3Slogwangto obtain the next available pseudo-terminal from the system.
911eaf0ac3SlogwangUpon success,
921eaf0ac3Slogwangit forks off a new process.
931eaf0ac3SlogwangIn the child process, it closes the descriptor
941eaf0ac3Slogwangfor the master side of the pty, and calls
951eaf0ac3Slogwang.Xr login_tty 3
961eaf0ac3Slogwangfor the slave pty.
971eaf0ac3SlogwangIn the parent process, it closes the descriptor for the
981eaf0ac3Slogwangslave side of the pty.
991eaf0ac3SlogwangThe arguments
1001eaf0ac3Slogwang.Fa amaster ,
1011eaf0ac3Slogwang.Fa name ,
1021eaf0ac3Slogwang.Fa termp ,
1031eaf0ac3Slogwangand
1041eaf0ac3Slogwang.Fa winp
1051eaf0ac3Slogwanghave the same meaning as described for
1061eaf0ac3Slogwang.Fn openpty .
1071eaf0ac3Slogwang.Sh RETURN VALUES
1081eaf0ac3SlogwangThe
1091eaf0ac3Slogwang.Fn openpty
1101eaf0ac3Slogwangfunction returns 0 on success, or -1 on failure.
1111eaf0ac3Slogwang.Pp
1121eaf0ac3SlogwangThe
1131eaf0ac3Slogwang.Fn forkpty
1141eaf0ac3Slogwangfunction returns -1 on failure, 0 in the slave process, and the process ID of
1151eaf0ac3Slogwangthe slave process in the parent process.
1161eaf0ac3Slogwang.Sh ERRORS
1171eaf0ac3SlogwangThe
1181eaf0ac3Slogwang.Fn openpty
1191eaf0ac3Slogwangfunction may fail and set the global variable
1201eaf0ac3Slogwang.Dv errno
1211eaf0ac3Slogwangfor any of the errors specified for the
1221eaf0ac3Slogwang.Xr grantpt 3 ,
1231eaf0ac3Slogwang.Xr posix_openpt 2 ,
1241eaf0ac3Slogwang.Xr ptsname 3 ,
1251eaf0ac3Slogwangand
1261eaf0ac3Slogwang.Xr unlockpt 3
1271eaf0ac3Slogwangfunctions and the
1281eaf0ac3Slogwang.Xr revoke 2
1291eaf0ac3Slogwangsystem call.
1301eaf0ac3Slogwang.Pp
1311eaf0ac3SlogwangIn addition to this,
1321eaf0ac3Slogwang.Fn forkpty
1331eaf0ac3Slogwangmay set it to any value as described for
1341eaf0ac3Slogwang.Xr fork 2 .
1351eaf0ac3Slogwang.Sh SEE ALSO
1361eaf0ac3Slogwang.Xr chmod 2 ,
1371eaf0ac3Slogwang.Xr chown 2 ,
1381eaf0ac3Slogwang.Xr fork 2 ,
1391eaf0ac3Slogwang.Xr getuid 2 ,
1401eaf0ac3Slogwang.Xr open 2 ,
1411eaf0ac3Slogwang.Xr revoke 2 ,
1421eaf0ac3Slogwang.Xr login_tty 3 ,
1431eaf0ac3Slogwang.Xr pty 4 ,
1441eaf0ac3Slogwang.Xr termios 4 ,
1451eaf0ac3Slogwang.Xr group 5
146*22ce4affSfengbojiang.Sh HISTORY
147*22ce4affSfengbojiangThe
148*22ce4affSfengbojiang.Fn openpty
149*22ce4affSfengbojiangand
150*22ce4affSfengbojiang.Fn forkpty
151*22ce4affSfengbojiangfunctions first appeared in
152*22ce4affSfengbojiang.Bx 4.3 Reno.
153*22ce4affSfengbojiang.Sh BUGS
154*22ce4affSfengbojiang.Fn openpty
155*22ce4affSfengbojiangwrites the slave terminal's name to
156*22ce4affSfengbojiang.Fa name ,
157*22ce4affSfengbojiangbut does not check that sufficient space is available.
158*22ce4affSfengbojiangIt is advisable to use
159*22ce4affSfengbojiang.Xr ptsname 3
160*22ce4affSfengbojianginstead.
161