diff options
| author | Joshua M. Clulow <josh@sysmgr.org> | 2022-02-21 22:48:06 -0800 |
|---|---|---|
| committer | Joshua M. Clulow <josh@sysmgr.org> | 2022-02-21 22:48:06 -0800 |
| commit | 1fa2a66491e7d8ae0be84e7da4da8e812480c710 (patch) | |
| tree | 1912c7ae9c69a1e0530357bb87a7dfa225fbec6f /usr/src/man | |
| parent | 74e98f497ae878ae481ccba1f91fd8dc26fa6627 (diff) | |
| download | illumos-joyent-1fa2a66491e7d8ae0be84e7da4da8e812480c710.tar.gz | |
14249 pseudo-terminal nomenclature should reflect POSIX
Reviewed by: Andy Fiddaman <andy@omnios.org>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Rich Lowe <richlowe@richlowe.net>
Approved by: Robert Mustacchi <rm@fingolfin.org>
Diffstat (limited to 'usr/src/man')
| -rw-r--r-- | usr/src/man/man1m/in.rlogind.1m | 10 | ||||
| -rw-r--r-- | usr/src/man/man1m/in.telnetd.1m | 11 | ||||
| -rw-r--r-- | usr/src/man/man1m/pppd.1m | 38 | ||||
| -rw-r--r-- | usr/src/man/man2/close.2 | 466 | ||||
| -rw-r--r-- | usr/src/man/man2/open.2 | 1770 | ||||
| -rw-r--r-- | usr/src/man/man3c/grantpt.3c | 154 | ||||
| -rw-r--r-- | usr/src/man/man3c/posix_openpt.3c | 286 | ||||
| -rw-r--r-- | usr/src/man/man3c/ptsname.3c | 123 | ||||
| -rw-r--r-- | usr/src/man/man3c/unlockpt.3c | 139 | ||||
| -rw-r--r-- | usr/src/man/man3utempter/utempter_add_record.3utempter | 6 | ||||
| -rw-r--r-- | usr/src/man/man7d/Makefile | 6 | ||||
| -rw-r--r-- | usr/src/man/man7d/ptm.7d | 338 | ||||
| -rw-r--r-- | usr/src/man/man7d/pts.7d | 107 | ||||
| -rw-r--r-- | usr/src/man/man7d/pty.7d | 495 | ||||
| -rw-r--r-- | usr/src/man/man7d/zcons.7d | 129 | ||||
| -rw-r--r-- | usr/src/man/man7m/pckt.7m | 13 | ||||
| -rw-r--r-- | usr/src/man/man7m/ptem.7m | 184 |
17 files changed, 2191 insertions, 2084 deletions
diff --git a/usr/src/man/man1m/in.rlogind.1m b/usr/src/man/man1m/in.rlogind.1m index fdddcee08d..4504cd5c8a 100644 --- a/usr/src/man/man1m/in.rlogind.1m +++ b/usr/src/man/man1m/in.rlogind.1m @@ -4,7 +4,7 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH IN.RLOGIND 1M "June 20, 2021" +.TH IN.RLOGIND 1M "February 5, 2022" .SH NAME in.rlogind, rlogind \- remote login server .SH SYNOPSIS @@ -82,9 +82,9 @@ client is present in \fB/etc/hosts.equiv\fR. See \fBhosts\fR(4) and .sp .LP Once the source port and address have been checked, \fBin.rlogind\fR allocates -a pseudo-terminal and manipulates file descriptors so that the slave half of -the pseudo-terminal becomes the \fBstdin\fR, \fBstdout\fR, and \fBstderr\fR for -a login process. The login process is an instance of the \fBlogin\fR(1) +a pseudo-terminal and manipulates file descriptors so that the subsidiary half +of the pseudo-terminal becomes the \fBstdin\fR, \fBstdout\fR, and \fBstderr\fR +for a login process. The login process is an instance of the \fBlogin\fR(1) program, invoked with the \fB-r\fR. .sp .LP @@ -93,7 +93,7 @@ process. See \fBSECURITY\fR below. If automatic authentication fails, it reprompts the user to login. .sp .LP -The parent of the login process manipulates the master side of the +The parent of the login process manipulates the manager side of the pseudo-terminal, operating as an intermediary between the login process and the client instance of the \fBrlogin\fR program. In normal operation, a packet protocol is invoked to provide Ctrl-S and Ctrl-Q type facilities and propagate diff --git a/usr/src/man/man1m/in.telnetd.1m b/usr/src/man/man1m/in.telnetd.1m index c233dccf49..b736fa082a 100644 --- a/usr/src/man/man1m/in.telnetd.1m +++ b/usr/src/man/man1m/in.telnetd.1m @@ -4,7 +4,7 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH IN.TELNETD 1M "June 20, 2021" +.TH IN.TELNETD 1M "February 5, 2022" .SH NAME in.telnetd, telnetd \- DARPA TELNET protocol server .SH SYNOPSIS @@ -22,10 +22,11 @@ the internet server (see \fBinetd\fR(1M)), for requests to connect to the .sp .LP \fBin.telnetd\fR operates by allocating a pseudo-terminal device for a client, -then creating a login process which has the slave side of the pseudo-terminal -as its standard input, output, and error. \fBin.telnetd\fR manipulates the -master side of the pseudo-terminal, implementing the \fBTELNET\fR protocol and -passing characters between the remote client and the login process. +then creating a login process which has the subsidiary side of the +pseudo-terminal as its standard input, output, and error. \fBin.telnetd\fR +manipulates the manager side of the pseudo-terminal, implementing the +\fBTELNET\fR protocol and passing characters between the remote client and the +login process. .sp .LP When a \fBTELNET\fR session starts up, \fBin.telnetd\fR sends \fBTELNET\fR diff --git a/usr/src/man/man1m/pppd.1m b/usr/src/man/man1m/pppd.1m index 8862ee9b94..4a2bdb360d 100644 --- a/usr/src/man/man1m/pppd.1m +++ b/usr/src/man/man1m/pppd.1m @@ -3,7 +3,7 @@ .\" Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by Carnegie Mellon University. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED .\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. .\" Portions Copyright (c) 2008, Sun Microsystems, Inc. All Right Reserved. -.TH PPPD 1M "November 22, 2021" +.TH PPPD 1M "February 5, 2022" .SH NAME pppd \- point to point protocol daemon .SH SYNOPSIS @@ -1301,11 +1301,11 @@ proxy ARP entries with \fBpppd\fR, place this option in the .sp .6 .RS 4n Normally, \fBpppd\fR requires a terminal device. With this option, \fBpppd\fR -allocates itself a pseudo-tty master/slave pair and uses the slave as its +allocates itself a pseudo-terminal pair and uses the subsidiary as its terminal device. \fBpppd\fR creates a child process to act as a character shunt -to transfer characters between the pseudo-tty master and its standard input and -output. Thus, \fBpppd\fR transmits characters on its standard output and -receives characters on its standard input even if they are not terminal +to transfer characters between the pseudo-terminal manager and its standard +input and output. Thus, \fBpppd\fR transmits characters on its standard output +and receives characters on its standard input even if they are not terminal devices. This option increases the latency and CPU overhead of transferring data over the ppp interface as all of the characters sent and received must flow through the character shunt process. An explicit device name may not be @@ -1506,12 +1506,12 @@ Ethernet interface. .sp .6 .RS 4n Specifies that the command \fIscript\fR, and not a specific terminal device is -used for serial communication. \fBpppd\fR allocates itself a pseudo-tty -master/slave pair and uses the slave as its terminal device. \fIscript\fR runs -in a child process with the pseudo-tty master as its standard input and output. -An explicit device name may not be given if this option is used. (Note: if the -\fBrecord\fR option is used in conjunction with the \fBpty\fR option, the child -process will have pipes on its standard input and output.) +used for serial communication. \fBpppd\fR allocates itself a pseudo-terminal +pair and uses the subsidiary as its terminal device. \fIscript\fR runs +in a child process with the pseudo-terminal manager as its standard input and +output. An explicit device name may not be given if this option is used. +(Note: if the \fBrecord\fR option is used in conjunction with the \fBpty\fR +option, the child process will have pipes on its standard input and output.) .RE .sp @@ -1537,14 +1537,14 @@ dial-back implementations. .RS 4n Directs \fBpppd\fR to record all characters sent and received to a file named \fIfilename\fR. \fIfilename\fR is opened in append mode, using the user's -user-ID and permissions. Because this option uses a pseudo-tty and a process to -transfer characters between the pseudo-tty and the real serial device, it -increases the latency and CPU overhead of transferring data over the PPP -interface. Characters are stored in a tagged format with timestamps that can be -displayed in readable form using the \fBpppdump\fR(1M) program. This option is -generally used when debugging the kernel portion of \fBpppd\fR (especially CCP -compression algorithms) and not for debugging link configuration problems. See -the \fBdebug\fR option. +user-ID and permissions. Because this option uses a pseudo-terminal and a +process to transfer characters between the pseudo-terminal and the real serial +device, it increases the latency and CPU overhead of transferring data over the +PPP interface. Characters are stored in a tagged format with timestamps that +can be displayed in readable form using the \fBpppdump\fR(1M) program. This +option is generally used when debugging the kernel portion of \fBpppd\fR +(especially CCP compression algorithms) and not for debugging link +configuration problems. See the \fBdebug\fR option. .RE .sp diff --git a/usr/src/man/man2/close.2 b/usr/src/man/man2/close.2 index ad1ff95b8f..281a3f8956 100644 --- a/usr/src/man/man2/close.2 +++ b/usr/src/man/man2/close.2 @@ -43,173 +43,193 @@ .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright 2022 Oxide Computer Company .\" -.TH CLOSE 2 "Oct 18, 2005" -.SH NAME -close \- close a file descriptor -.SH SYNOPSIS -.LP -.nf -#include <unistd.h> - -\fBint\fR \fBclose\fR(\fBint\fR \fIfildes\fR); -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBclose()\fR function deallocates the file descriptor indicated by -\fIfildes\fR. To deallocate means to make the file descriptor available for -return by subsequent calls to \fBopen\fR(2) or other functions that allocate -file descriptors. All outstanding record locks owned by the process on the file -associated with the file descriptor will be removed (that is, unlocked). -.sp -.LP -If \fBclose()\fR is interrupted by a signal that is to be caught, it will -return \fB\(mi1\fR with \fBerrno\fR set to \fBEINTR\fR and the state of -\fIfildes\fR is unspecified. If an I/O error occurred while reading from or -writing to the file system during \fBclose()\fR, it returns -1, sets -\fBerrno\fR to \fBEIO\fR, and the state of \fIfildes\fR is unspecified. -.sp -.LP -When all file descriptors associated with a pipe or \fBFIFO\fR special file are -closed, any data remaining in the pipe or \fBFIFO\fR will be discarded. -.sp -.LP +.Dd February 5, 2022 +.Dt CLOSE 2 +.Os +.Sh NAME +.Nm close +.Nd close a file descriptor +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fo close +.Fa "int fildes" +.Fc +.Sh DESCRIPTION +The +.Fn close +function deallocates the file descriptor indicated by +.Fa fildes . +To deallocate means to make the file descriptor available for return by +subsequent calls to +.Xr open 2 +or other functions that allocate file descriptors. +All outstanding record locks owned by the process on the file associated with +the file descriptor will be removed +.Pq "that is, unlocked" . +.Pp +If +.Fn close +is interrupted by a signal that is to be caught, it will return +.Sy -1 +with +.Va errno +set to +.Er EINTR +and the state of +.Fa fildes +is unspecified. +If an I/O error occurred while reading from or writing to the file system during +.Fn close , +it returns +.Sy -1 , +sets +.Va errno +to +.Er EIO , +and the state of +.Fa fildes +is unspecified. +.Pp +When all file descriptors associated with a pipe or FIFO special file are +closed, any data remaining in the pipe or FIFO will be discarded. +.Pp When all file descriptors associated with an open file description have been closed the open file description will be freed. -.sp -.LP -If the link count of the file is 0, when all file descriptors associated with -the file are closed, the space occupied by the file will be freed and the file -will no longer be accessible. -.sp -.LP -If a streams-based (see \fBIntro\fR(2)) \fIfildes\fR is closed and the calling -process was previously registered to receive a \fBSIGPOLL\fR signal (see -\fBsignal\fR(3C)) for events associated with that stream (see \fBI_SETSIG\fR in -\fBstreamio\fR(7I)), the calling process will be unregistered for events -associated with the stream. The last \fBclose()\fR for a stream causes the -stream associated with \fIfildes\fR to be dismantled. If \fBO_NONBLOCK\fR and -\fBO_NDELAY\fR are not set and there have been no signals posted for the -stream, and if there is data on the module's write queue, \fBclose()\fR waits -up to 15 seconds (for each module and driver) for any output to drain before -dismantling the stream. The time delay can be changed via an \fBI_SETCLTIME\fR -\fBioctl\fR(2) request (see \fBstreamio\fR(7I)). If the \fBO_NONBLOCK\fR or -\fBO_NDELAY\fR flag is set, or if there are any pending signals, \fBclose()\fR +.Pp +If the link count of the file is +.Sy 0 , +when all file descriptors associated with the file are closed, the space +occupied by the file will be freed and the file will no longer be accessible. +.Pp +If a streams-based +.Po +see +.Xr Intro 2 +.Pc +.Fa fildes +is closed and the calling process was previously registered to receive a +.Dv SIGPOLL +signal +.Po +see +.Xr signal 3C +.Pc +for events associated with that stream +.Po +see +.Dv I_SETSIG +in +.Xr streamio 7I +.Pc , +the calling process will be unregistered for events associated with the stream. +The last +.Fn close +for a stream causes the stream associated with +.Fa fildes +to be dismantled. +If +.Dv O_NONBLOCK +and +.Dv O_NDELAY +are not set and there have been no signals posted for the stream, and if there +is data on the module's write queue, +.Fn close +waits up to 15 seconds +.Pq for each module and driver +for any output to drain +before dismantling the stream. +The time delay can be changed via an +.Dv I_SETCLTIME +.Xr ioctl 2 +request +.Po +see +.Xr streamio 7I +.Pc . +If the +.Dv O_NONBLOCK +or +.Dv O_NDELAY +flag is set, or if there are any pending signals, +.Fn close does not wait for output to drain, and dismantles the stream immediately. -.sp -.LP -If \fIfildes\fR is associated with one end of a pipe, the last \fBclose()\fR -causes a hangup to occur on the other end of the pipe. In addition, if the -other end of the pipe has been named by \fBfattach\fR(3C), then the last -\fBclose()\fR forces the named end to be detached by \fBfdetach\fR(3C). If the -named end has no open file descriptors associated with it and gets detached, -the stream associated with that end is also dismantled. -.sp -.LP -If \fIfildes\fR refers to the master side of a pseudo-terminal, a \fBSIGHUP\fR -signal is sent to the session leader, if any, for which the slave side of the -pseudo-terminal is the controlling terminal. It is unspecified whether closing -the master side of the pseudo-terminal flushes all queued input and output. -.sp -.LP -If \fIfildes\fR refers to the slave side of a streams-based pseudo-terminal, a -zero-length message may be sent to the master. -.sp -.LP +.Pp +If +.Fa fildes +is associated with one end of a pipe, the last +.Fn close +causes a hangup to occur on the other end of the pipe. +In addition, if the other end of the pipe has been named by +.Xr fattach 3C , +then the last +.Fn close +forces the named end to be detached by +.Xr fdetach 3C . +If the named end has no open file descriptors associated with it and gets +detached, the stream associated with that end is also dismantled. +.Pp +If +.Fa fildes +refers to the manager side of a pseudo-terminal, a +.Dv SIGHUP +signal is sent to the session leader, if any, for which the subsidiary side of +the pseudo-terminal is the controlling terminal. +It is unspecified whether closing the manager side of the pseudo-terminal +flushes all queued input and output. +.Pp +If +.Fa fildes +refers to the subsidiary side of a streams-based pseudo-terminal, a zero-length +message may be sent to the manager. +.Pp When there is an outstanding cancelable asynchronous I/O operation against -\fIfildes\fR when \fBclose()\fR is called, that I/O operation is canceled. An -I/O operation that is not canceled completes as if the \fBclose()\fR operation -had not yet occurred. All operations that are not canceled will complete as if -the \fBclose()\fR blocked until the operations completed. -.sp -.LP +.Fa fildes +when +.Fn close +is called, that I/O operation is canceled. +An I/O operation that is not canceled completes as if the +.Fn close +operation had not yet occurred. +All operations that are not canceled will complete as if the +.Fn close +blocked until the operations completed. +.Pp If a shared memory object or a memory mapped file remains referenced at the -last close (that is, a process has it mapped), then the entire contents of the -memory object will persist until the memory object becomes unreferenced. If -this is the last close of a shared memory object or a memory mapped file and +last close +.Pq "that is, a process has it mapped" , +then the entire contents of the memory object will persist until the memory +object becomes unreferenced. +If this is the last close of a shared memory object or a memory mapped file and the close results in the memory object becoming unreferenced, and the memory object has been unlinked, then the memory object will be removed. -.sp -.LP -If \fIfildes\fR refers to a socket, \fBclose()\fR causes the socket to be -destroyed. If the socket is connection-mode, and the \fBSO_LINGER\fR option is -set for the socket with non-zero linger time, and the socket has untransmitted -data, then \fBclose()\fR will block for up to the current linger interval until -all data is transmitted. -.SH RETURN VALUES -.sp -.LP -Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is -returned and \fBerrno\fR is set to indicate the error. -.SH ERRORS -.sp -.LP -The \fBclose()\fR function will fail if: -.sp -.ne 2 -.na -\fB\fBEBADF\fR\fR -.ad -.RS 11n -The \fIfildes\fR argument is not a valid file descriptor. -.RE - -.sp -.ne 2 -.na -\fB\fBEINTR\fR\fR -.ad -.RS 11n -The \fBclose()\fR function was interrupted by a signal. -.RE - -.sp -.ne 2 -.na -\fB\fBENOLINK\fR\fR -.ad -.RS 11n -The \fIfildes\fR argument is on a remote machine and the link to that machine -is no longer active. -.RE - -.sp -.ne 2 -.na -\fB\fBENOSPC\fR\fR -.ad -.RS 11n -There was no free space remaining on the device containing the file. -.RE - -.sp -.LP -The \fBclose()\fR function may fail if: -.sp -.ne 2 -.na -\fB\fBEIO\fR\fR -.ad -.RS 7n -An I/O error occurred while reading from or writing to the file system. -.RE - -.SH EXAMPLES -.LP -\fBExample 1 \fRReassign a file descriptor. -.sp -.LP +.Pp +If +.Fa fildes +refers to a socket, +.Fn close +causes the socket to be destroyed. +If the socket is connection-mode, and the +.Dv SO_LINGER +option is set for the socket with non-zero linger time, and the socket has +untransmitted data, then +.Fn close +will block for up to the current linger interval until all data is transmitted. +.Sh RETURN VALUES +.Rv -std close +.Sh EXAMPLES +.Sy Example 1 +Reassign a file descriptor. +.Pp The following example closes the file descriptor associated with standard output for the current process, re-assigns standard output to a new file -descriptor, and closes the original file descriptor to clean up. This example -assumes that the file descriptor 0, which is the descriptor for standard input, -is not closed. - -.sp -.in +2 -.nf +descriptor, and closes the original file descriptor to clean up. +This example assumes that the file descriptor +.Sy 0 , +which is the descriptor for standard input, is not closed. +.Bd -literal -offset Ds #include <unistd.h> \&... int pfd; @@ -218,32 +238,22 @@ close(1); dup(pfd); close(pfd); \&... -.fi -.in -2 - -.sp -.LP +.Ed +.Pp Incidentally, this is exactly what could be achieved using: - -.sp -.in +2 -.nf +.Bd -literal -offset Ds dup2(pfd, 1); close(pfd); -.fi -.in -2 - -.LP -\fBExample 2 \fRClose a file descriptor. -.sp -.LP -In the following example, \fBclose()\fR is used to close a file descriptor -after an unsuccessful attempt is made to associate that file descriptor with a -stream. - -.sp -.in +2 -.nf +.Ed +.Pp +.Sy Example 2 +Close a file descriptor. +.Pp +In the following example, +.Fn close +is used to close a file descriptor after an unsuccessful attempt is made to +associate that file descriptor with a stream. +.Bd -literal -offset Ds #include <stdio.h> #include <unistd.h> #include <stdlib.h> @@ -259,38 +269,64 @@ if ((fpfd = fdopen (pfd, "w")) == NULL) { exit(1); } \&... -.fi -.in -2 - -.SH USAGE -.sp -.LP -An application that used the \fBstdio\fR function \fBfopen\fR(3C) to open a -file should use the corresponding \fBfclose\fR(3C) function rather than -\fBclose()\fR. -.SH ATTRIBUTES -.sp -.LP -See \fBattributes\fR(5) for descriptions of the following attributes: -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -Interface Stability Standard -_ -MT-Level Async-Signal-Safe -.TE - -.SH SEE ALSO -.sp -.LP -\fBIntro\fR(2), \fBcreat\fR(2), \fBdup\fR(2), \fBexec\fR(2), \fBfcntl\fR(2), -\fBioctl\fR(2), \fBopen\fR(2) \fBpipe\fR(2), \fBfattach\fR(3C), -\fBfclose\fR(3C), \fBfdetach\fR(3C), \fBfopen\fR(3C), \fBsignal\fR(3C), -\fBsignal.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5), -\fBstreamio\fR(7I) +.Ed +.Sh ERRORS +The +.Fn close +function will fail if: +.Bl -tag -width Er +.It Er EBADF +The +.Fa fildes +argument is not a valid file descriptor. +.It Er EINTR +The +.Fn close +function was interrupted by a signal. +.It Er ENOLINK +The +.Fa fildes +argument is on a remote machine and the link to that machine is no longer +active. +.It Er ENOSPC +There was no free space remaining on the device containing the file. +.El +.Pp +The +.Fn close +function may fail if: +.Bl -tag -width Er +.It Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh USAGE +An application that used the +.Xr stdio 3C +function +.Xr fopen 3C +to open a file should use the corresponding +.Xr fclose 3C +function rather than +.Fn close . +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT-LEVEL +.Sy Async-Signal-Safe +.Sh SEE ALSO +.Xr creat 2 , +.Xr dup 2 , +.Xr exec 2 , +.Xr fcntl 2 , +.Xr Intro 2 , +.Xr ioctl 2 , +.Xr open 2 , +.Xr pipe 2 , +.Xr fattach 3C , +.Xr fclose 3C , +.Xr fdetach 3C , +.Xr fopen 3C , +.Xr signal 3C , +.Xr signal.h 3HEAD , +.Xr attributes 5 , +.Xr standards 5 , +.Xr streamio 7I diff --git a/usr/src/man/man2/open.2 b/usr/src/man/man2/open.2 index aa9048c660..ce23eac084 100644 --- a/usr/src/man/man2/open.2 +++ b/usr/src/man/man2/open.2 @@ -47,879 +47,586 @@ .\" All Rights Reserved. .\" Copyright 2015 Nexenta Systems, Inc. All rights reserved. .\" Copyright 2020 Joyent, Inc. +.\" Copyright 2022 Oxide Computer Company .\" -.TH OPEN 2 "Mar 10, 2020" -.SH NAME -open, openat \- open a file -.SH SYNOPSIS -.nf -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -\fBint\fR \fBopen\fR(\fBconst char *\fR\fIpath\fR, \fBint\fR \fIoflag\fR, \fB/* mode_t\fR \fImode\fR */); -.fi - -.LP -.nf -\fBint\fR \fBopenat\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fIpath\fR, \fBint\fR \fIoflag\fR, - \fB/* mode_t\fR \fImode\fR */); -.fi - -.SH DESCRIPTION -The \fBopen()\fR function establishes the connection between a file and a file -descriptor. It creates an open file description that refers to a file and a -file descriptor that refers to that open file description. The file descriptor -is used by other I/O functions to refer to that file. The \fIpath\fR argument -points to a pathname naming the file. -.sp -.LP -The \fBopenat()\fR function is identical to the \fBopen()\fR function except -that the \fIpath\fR argument is interpreted relative to the starting point -implied by the \fIfildes\fR argument. If the \fIfildes\fR argument has the -special value \fBAT_FDCWD\fR, a relative path argument will be resolved -relative to the current working directory. If the \fIpath\fR argument is -absolute, the \fIfildes\fR argument is ignored. -.sp -.LP -The \fBopen()\fR function returns a file descriptor for the named file that is -the lowest file descriptor not currently open for that process. The open file -description is new, and therefore the file descriptor does not share it with -any other process in the system. The \fBFD_CLOEXEC\fR file descriptor flag -associated with the new file descriptor is cleared. -.sp -.LP +.Dd February 5, 2022 +.Dt OPEN 2 +.Os +.Sh NAME +.Nm open , +.Nm openat +.Nd open a file +.Sh SYNOPSIS +.In sys/types.h +.In sys/stat.h +.In fcntl.h +.Ft int +.Fo open +.Fa "const char *path" +.Fa "int oflag" +.Op , Fa "mode_t mode" +.Fc +.Ft int +.Fo openat +.Fa "int fildes" +.Fa "const char *path" +.Fa "int oflag" +.Op , Fa "mode_t mode" +.Fc +.Sh DESCRIPTION +The +.Fn open +function establishes the connection between a file and a file descriptor. +It creates an open file description that refers to a file and a file descriptor +that refers to that open file description. +The file descriptor is used by other I/O functions to refer to that file. +The +.Fa path +argument points to a pathname naming the file. +.Pp +The +.Fn openat +function is identical to the +.Fn open +function except +that the +.Fa path +argument is interpreted relative to the starting point +implied by the +.Fa fildes +argument. +If the +.Fa fildes +argument has the special value +.Dv AT_FDCWD , +a relative path argument will be resolved relative to the current working +directory. +If the +.Fa path +argument is absolute, the +.Fa fildes +argument is ignored. +.Pp +The +.Fn open +function returns a file descriptor for the named file that is the lowest file +descriptor not currently open for that process. +The open file description is new, and therefore the file descriptor does not +share it with any other process in the system. +The +.Dv FD_CLOEXEC +file descriptor flag associated with the new file descriptor is cleared. +.Pp The file offset used to mark the current position within the file is set to the beginning of the file. -.sp -.LP +.Pp The file status flags and file access modes of the open file description are -set according to the value of \fIoflag\fR. The \fImode\fR argument is used only -when \fBO_CREAT\fR is specified (see below.) -.sp -.LP -Values for \fIoflag\fR are constructed by a bitwise-inclusive-OR of flags from -the following list, defined in <\fBfcntl.h\fR>. Applications must specify -exactly one of the first three values (file access modes) below in the value of -\fIoflag\fR: -.sp -.ne 2 -.na -\fB\fBO_RDONLY\fR\fR -.ad -.RS 12n +set according to the value of +.Fa oflag . +The +.Fa mode +argument is used only +when +.Dv O_CREAT +is specified +.Pq "see below" . +.Pp +Values for +.Fa oflag +are constructed by a bitwise-inclusive-OR of flags from +the following list, defined in +.Xr fcntl.h 3HEAD . +Applications must specify exactly one of the first three values (file access +modes) below in the value of +.Fa oflag : +.Bl -tag -width Ds +.It Dv O_RDONLY Open for reading only. -.RE - -.sp -.ne 2 -.na -\fB\fBO_WRONLY\fR\fR -.ad -.RS 12n +.It Dv O_WRONLY Open for writing only. -.RE - -.sp -.ne 2 -.na -\fB\fBO_RDWR\fR\fR -.ad -.RS 12n -Open for reading and writing. The result is undefined if this flag is applied -to a FIFO. -.RE - -.sp -.LP +.It Dv O_RDWR +Open for reading and writing. +The result is undefined if this flag is applied to a FIFO. +.El +.Pp Any combination of the following may be used: -.sp -.ne 2 -.na -\fB\fBO_APPEND\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -tag -width Ds +.It Dv O_APPEND If set, the file offset is set to the end of the file prior to each write. -.RE - -.sp -.ne 2 -.na -\fB\fBO_CREAT\fR\fR -.ad -.sp .6 -.RS 4n -Create the file if it does not exist. This flag requires that the \fImode\fR +.It Dv O_CREAT +Create the file if it does not exist. +This flag requires that the +.Fa mode argument be specified. -.sp -If the file exists, this flag has no effect except as noted under \fBO_EXCL\fR -below. Otherwise, the file is created with the user \fBID\fR of the file set -to the effective user \fBID\fR of the process. The group \fBID\fR of the file -is set to the effective group \fBIDs\fR of the process, or if the \fBS_ISGID\fR +.Pp +If the file exists, this flag has no effect except as noted under +.Dv O_EXCL +below. +Otherwise, the file is created with the user ID of the file set to the +effective user ID of the process. +The group ID of the file is set to the effective group IDs of the process, or +if the +.Dv S_ISGID bit is set in the directory in which the file is being created, the file's -group \fBID\fR is set to the group \fBID\fR of its parent directory. If the -group \fBID\fR of the new file does not match the effective group \fBID\fR or -one of the supplementary groups IDs, the \fBS_ISGID\fR bit is cleared. The -access permission bits (see \fB<sys/stat.h>\fR) of the file mode are set to the -value of \fImode\fR, modified as follows (see \fBcreat\fR(2)): a bitwise-AND is -performed on the file-mode bits and the corresponding bits in the complement of -the process's file mode creation mask. Thus, all bits set in the process's file -mode creation mask (see \fBumask\fR(2)) are correspondingly cleared in the -file's permission mask. The "save text image after execution bit" of the mode -is cleared (see \fBchmod\fR(2)). When bits other than the file permission bits -are set, the effect is unspecified. The \fImode\fR argument does not affect -whether the file is open for reading, writing or for both. -.RE - -.sp -.ne 2 -.na -.B O_DIRECT -.ad -.sp .6 -.RS 4n +group ID is set to the group ID of its parent directory. +If the group ID of the new file does not match the effective group +ID or one of the supplementary groups IDs, the +.Dv S_ISGID bit is cleared. +.Pp +The access permission bits +.Po +see +.Xr stat.h 3HEAD +.Pc +of the file mode are set to the value of +.Fa mode , +modified as follows +.Po +see +.Xr creat 2 +.Pc : +a bitwise-AND is performed on the file-mode bits and the corresponding bits in +the complement of the process's file mode creation mask. +Thus, all bits set in the process's file mode creation mask +.Po +see +.Xr umask 2 +.Pc +are correspondingly cleared in the file's permission mask. +The +.Dq save text image after execution bit +of the mode is cleared +.Po +see +.Xr chmod 2 +.Pc . +When bits other than the file permission bits are set, the effect is +unspecified. +The +.Fa mode +argument does not affect whether the file is open for reading, writing or for +both. +.It Dv O_DIRECT Indicates that the file data is not going to be reused in the near future. When possible, data is read or written directly between the application's -memory and the device when the data is accessed with \fBread\fR(2) and -\fBwrite\fR(2) operations. See \fBdirectio\fR(3C) for more details. -.RE - -.sp -.ne 2 -.na -.B O_DIRECTORY -.ad -.sp .6 -.RS 4n +memory and the device when the data is accessed with +.Xr read 2 +and +.Xr write 2 +operations. +See +.Xr directio 3C +for more details. +.It Dv O_DIRECTORY Indicates that attempts to open -.I path +.Fa path should fail unless -.I path +.Fa path is a directory. If both -.B O_CREAT +.Dv O_CREAT and -.B O_DIRECTORY +.Dv O_DIRECTORY are specified then the call will fail if it would result in a file being created. If a directory already exists at -.I path +.Fa path then it will behave as if the -.B O_DIRECTORY +.Dv O_DIRECTORY flag had not been present. If the -.B O_EXCL +.Dv O_EXCL and -.B O_CREAT -flags are specified, then the call will always fail as they imply a file -should always be created. -.RE - -.sp -.ne 2 -.na -\fB\fBO_DSYNC\fR\fR -.ad -.sp .6 -.RS 4n +.Dv O_CREAT +flags are specified, then the call will always fail as they imply a file should +always be created. +.It Dv O_DSYNC Write I/O operations on the file descriptor complete as defined by synchronized I/O data integrity completion. -.RE - -.sp -.ne 2 -.na -\fB\fBO_EXCL\fR\fR -.ad -.sp .6 -.RS 4n -If \fBO_CREAT\fR and \fBO_EXCL\fR are set, \fBopen()\fR fails if the file -exists. The check for the existence of the file and the creation of the file if +.It Dv O_EXCL +If +.Dv O_CREAT +and +.Dv O_EXCL +are set, +.Fn open +fails if the file exists. +The check for the existence of the file and the creation of the file if it does not exist is atomic with respect to other threads executing -\fBopen()\fR naming the same filename in the same directory with \fBO_EXCL\fR -and \fBO_CREAT\fR set. If \fBO_EXCL\fR and \fBO_CREAT\fR are set, and path -names a symbolic link, \fBopen()\fR fails and sets \fBerrno\fR to \fBEEXIST\fR, -regardless of the contents of the symbolic link. If \fBO_EXCL\fR is set and -\fBO_CREAT\fR is not set, the result is undefined. -.RE - -.sp -.ne 2 -.na -.B O_EXEC -.na -.ad -.sp .6 -.RS 4n +.Fn open +naming the same filename in the same directory with +.Dv O_EXCL +and +.Dv O_CREAT +set. +If +.Dv O_EXCL +and +.Dv O_CREAT +are set, and +.Fa path +names a symbolic link, +.Fn open +fails and sets +.Va errno +to +.Er EEXIST , +regardless of the contents of the symbolic link. +If +.Dv O_EXCL +is set and +.Dv O_CREAT +is not set, the result is undefined. +.It Dv O_EXEC If set, indicates that the file should be opened for execute permission. -This option is only valid for regular files, an error will be returned -if it is not. -.RE - -.sp -.ne 2 -.na -\fB\fBO_LARGEFILE\fR\fR -.ad -.sp .6 -.RS 4n +This option is only valid for regular files; an error will be returned if the +target is not a regular file. +.It Dv O_LARGEFILE If set, the offset maximum in the open file description is the largest value -that can be represented correctly in an object of type \fBoff64_t\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBO_NOCTTY\fR\fR -.ad -.sp .6 -.RS 4n -If set and \fIpath\fR identifies a terminal device, \fBopen()\fR does not cause -the terminal device to become the controlling terminal for the process. -.RE - -.sp -.ne 2 -.na -\fB\fBO_NOFOLLOW\fR\fR -.ad -.sp .6 -.RS 4n -If the path names a symbolic link, \fBopen()\fR fails and sets \fBerrno\fR to -\fBELOOP\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBO_NOLINKS\fR\fR -.ad -.sp .6 -.RS 4n -If the link count of the named file is greater than 1, \fBopen()\fR fails and -sets \fBerrno\fR to \fBEMLINK\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBO_CLOEXEC\fR\fR -.ad -.sp .6 -.RS 4n +that can be represented correctly in an object of type +.Vt off64_t . +.It Dv O_NOCTTY +If set and +.Fa path +identifies a terminal device, +.Fn open +does not cause the terminal device to become the controlling terminal for the +process. +.It Dv O_NOFOLLOW +If the path names a symbolic link, +.Fn open +fails and sets +.Va errno +to +.Er ELOOP . +.It Dv O_NOLINKS +If the link count of the named file is greater than +.Sy 1 , +.Fn open +fails and sets +.Va errno +to +.Er EMLINK . +.It Dv O_CLOEXEC If set, the file descriptor returned will be closed prior to any future -\fBexec()\fR calls. -.RE - -.sp -.ne 2 -.na -\fB\fBO_NONBLOCK\fR or \fBO_NDELAY\fR\fR -.ad -.sp .6 -.RS 4n -These flags can affect subsequent reads and writes (see \fBread\fR(2) and -\fBwrite\fR(2)). If both \fBO_NDELAY\fR and \fBO_NONBLOCK\fR are set, -\fBO_NONBLOCK\fR takes precedence. -.sp -When opening a \fBFIFO\fR with \fBO_RDONLY\fR or \fBO_WRONLY\fR set: -.RS +4 -.TP -.ie t \(bu -.el o -If \fBO_NONBLOCK\fR or \fBO_NDELAY\fR is set, an \fBopen()\fR for reading only -returns without delay. An \fBopen()\fR for writing only returns an error if no -process currently has the file open for reading. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -If \fBO_NONBLOCK\fR and \fBO_NDELAY\fR are clear, an \fBopen()\fR for reading -only blocks until a thread opens the file for writing. An \fBopen()\fR for -writing only blocks the calling thread until a thread opens the file for +.Xr exec 2 +calls. +.It Dv O_NONBLOCK O_NDELAY +These flags can affect subsequent reads and writes +.Po +see +.Xr read 2 +and +.Xr write 2 +.Pc . +If both +.Dv O_NDELAY +and +.Dv O_NONBLOCK +are set, +.Dv O_NONBLOCK +takes precedence. +.Pp +When opening a FIFO with +.Dv O_RDONLY +or +.Dv O_WRONLY +set: +.Bl -bullet +.It +If +.Dv O_NONBLOCK +or +.Dv O_NDELAY +is set, an +.Fn open +for reading only returns without delay. +An +.Fn open +for writing only returns an error if no process currently has the file open for reading. -.RE -After both ends of a \fBFIFO\fR have been opened, there is no guarantee that -further calls to \fBopen()\fR \fBO_RDONLY\fR (\fBO_WRONLY\fR) will synchronize -with later calls to \fBopen()\fR \fBO_WRONLY\fR (\fBO_RDONLY\fR) until both -ends of the \fBFIFO\fR have been closed by all readers and writers. Any data -written into a \fBFIFO\fR will be lost if both ends of the \fBFIFO\fR are -closed before the data is read. -.sp +.It +If +.Dv O_NONBLOCK +and +.Dv O_NDELAY +are clear, an +.Fn open +for reading only blocks until a thread opens the file for writing. +An +.Fn open +for writing only blocks the calling thread until a thread opens the file for +reading. +.El +.Pp +After both ends of a FIFO have been opened once, there is no guarantee that +further calls to +.Fn open +.Dv O_RDONLY +.Pq Dv O_WRONLY +will synchronize with later calls to +.Fn open +.Dv O_WRONLY +.Pq Dv O_RDONLY +until both ends of the FIFO have been closed by all readers and writers. +Any data written into a FIFO will be lost if both ends of the FIFO are closed +before the data is read. +.Pp When opening a block special or character special file that supports non-blocking opens: -.RS +4 -.TP -.ie t \(bu -.el o -If \fBO_NONBLOCK\fR or \fBO_NDELAY\fR is set, the \fBopen()\fR function returns -without blocking for the device to be ready or available. Subsequent behavior -of the device is device-specific. -.RE -.RS +4 -.TP -.ie t \(bu -.el o -If \fBO_NONBLOCK\fR and \fBO_NDELAY\fR are clear, the \fBopen()\fR function -blocks the calling thread until the device is ready or available before -returning. -.RE -Otherwise, the behavior of \fBO_NONBLOCK\fR and \fBO_NDELAY\fR is unspecified. -.RE - -.sp -.ne 2 -.na -\fB\fBO_RSYNC\fR\fR -.ad -.sp .6 -.RS 4n +.Bl -bullet +.It +If +.Dv O_NONBLOCK +or +.Dv O_NDELAY +is set, the +.Fn open +function returns without blocking for the device to be ready or available. +Subsequent behavior of the device is device-specific. +.It +If +.Dv O_NONBLOCK +and +.Dv O_NDELAY +are clear, the +.Fn open +function blocks the calling thread until the device is ready or available +before returning. +.El +.Pp +Otherwise, the behavior of +.Dv O_NONBLOCK +and +.Dv O_NDELAY +is unspecified. +.It Dv O_RSYNC Read I/O operations on the file descriptor complete at the same level of -integrity as specified by the \fBO_DSYNC\fR and \fBO_SYNC\fR flags. If both -\fBO_DSYNC\fR and \fBO_RSYNC\fR are set in \fIoflag\fR, all I/O operations on -the file descriptor complete as defined by synchronized I/O data integrity -completion. If both \fBO_SYNC\fR and \fBO_RSYNC\fR are set in \fIoflag\fR, all -I/O operations on the file descriptor complete as defined by synchronized I/O -file integrity completion. -.RE - -.sp -.ne 2 -.na -.B O_SEARCH -.ad -.sp .6 -.RS 4n +integrity as specified by the +.Dv O_DSYNC +and +.Dv O_SYNC +flags. +If both +.Dv O_DSYNC +and +.Dv O_RSYNC +are set in +.Fa oflag , +all I/O operations on the file descriptor complete as defined by synchronized +I/O data integrity completion. +If both +.Dv O_SYNC +and +.Dv O_RSYNC +are set in +.Fa oflag , +all I/O operations on the file descriptor complete as defined by synchronized +I/O file integrity completion. +.It Dv O_SEARCH If set, indicates that the directory should be opened for searching. -This option is only valid for a directory, an error will be returned if -it is not. -.RE - -.sp -.ne 2 -.na -\fB\fBO_SYNC\fR\fR -.ad -.sp .6 -.RS 4n +This option is only valid for a directory; an error will be returned if the +target is not a directory. +.It Dv O_SYNC Write I/O operations on the file descriptor complete as defined by synchronized -I/O file integrity completion (see \fBfcntl.h\fR(3HEAD) definition of -\fBO_SYNC\fR). -.RE - -.sp -.ne 2 -.na -\fB\fBO_TRUNC\fR\fR -.ad -.sp .6 -.RS 4n +I/O file integrity completion +.Po +see +.Xr fcntl.h 3HEAD +.Pc +definition of +.Dv O_SYNC . +.It Dv O_TRUNC If the file exists and is a regular file, and the file is successfully opened -\fBO_RDWR\fR or \fBO_WRONLY\fR, its length is truncated to 0 and the mode and -owner are unchanged. It has no effect on \fBFIFO\fR special files or terminal -device files. Its effect on other file types is implementation-dependent. The -result of using \fBO_TRUNC\fR with \fBO_RDONLY\fR is undefined. -.RE - -.sp -.ne 2 -.na -\fB\fBO_XATTR\fR\fR -.ad -.sp .6 -.RS 4n -If set in \fBopenat()\fR, a relative path argument is interpreted as a -reference to an extended attribute of the file associated with the supplied -file descriptor. This flag therefore requires the presence of a legal -\fIfildes\fR argument. If set in \fBopen()\fR, the implied file descriptor is -that for the current working directory. Extended attributes must be referenced -with a relative path; providing an absolute path results in a normal file -reference. -.RE - -.sp -.LP -If \fBO_CREAT\fR is set and the file did not previously exist, upon successful -completion, \fBopen()\fR marks for update the \fBst_atime\fR, \fBst_ctime\fR, -and \fBst_mtime\fR fields of the file and the \fBst_ctime\fR and \fBst_mtime\fR +.Dv O_RDWR +or +.Dv O_WRONLY , +its length is truncated to +.Sy 0 +and the mode and owner are unchanged. +It has no effect on FIFO special files or terminal device files. +Its effect on other file types is implementation-dependent. +The result of using +.Dv O_TRUNC +with +.Dv O_RDONLY +is undefined. +.It Dv O_XATTR +If set in +.Fn openat , +a relative path argument is interpreted as a reference to an extended attribute +of the file associated with the supplied file descriptor. +This flag therefore requires the presence of a legal +.Fa fildes +argument. +If set in +.Fn open , +the implied file descriptor is that for the current working directory. +Extended attributes must be referenced with a relative path; providing an +absolute path results in a normal file reference. +.El +.Pp +If +.Dv O_CREAT +is set and the file did not previously exist, upon successful completion, +.Fn open +marks for update the +.Fa st_atime , +.Fa st_ctime , +and +.Fa st_mtime +fields of the file and the +.Fa st_ctime +and +.Fa st_mtime fields of the parent directory. -.sp -.LP -If \fBO_TRUNC\fR is set and the file did previously exist, upon successful -completion, \fBopen()\fR marks for update the \fBst_ctime\fR and \fBst_mtime\fR +.Pp +If +.Dv O_TRUNC +is set and the file did previously exist, upon successful completion, +.Fn open +marks for update the +.Fa st_ctime +and +.Fa st_mtime fields of the file. -.sp -.LP -If both the \fBO_SYNC\fR and \fBO_DSYNC\fR flags are set, the effect is as if -only the \fBO_SYNC\fR flag was set. -.sp -.LP -If \fIpath\fR refers to a \fBSTREAMS\fR file, \fIoflag\fR may be constructed -from \fBO_NONBLOCK\fR or \fBO_NODELAY\fR OR-ed with either \fBO_RDONLY\fR, -\fBO_WRONLY\fR, or \fBO_RDWR\fR. Other flag values are not applicable to -\fBSTREAMS\fR devices and have no effect on them. The values \fBO_NONBLOCK\fR -and \fBO_NODELAY\fR affect the operation of \fBSTREAMS\fR drivers and certain -functions (see \fBread\fR(2), \fBgetmsg\fR(2), \fBputmsg\fR(2), and -\fBwrite\fR(2)) applied to file descriptors associated with \fBSTREAMS\fR -files. For \fBSTREAMS\fR drivers, the implementation of \fBO_NONBLOCK\fR and -\fBO_NODELAY\fR is device-specific. -.sp -.LP -When \fBopen()\fR is invoked to open a named stream, and the \fBconnld\fR -module (see \fBconnld\fR(7M)) has been pushed on the pipe, \fBopen()\fR blocks -until the server process has issued an \fBI_RECVFD\fR \fBioctl()\fR (see -\fBstreamio\fR(7I)) to receive the file descriptor. -.sp -.LP -If \fIpath\fR names the master side of a pseudo-terminal device, then it is -unspecified whether \fBopen()\fR locks the slave side so that it cannot be -opened. Portable applications must call \fBunlockpt\fR(3C) before opening the -slave side. -.sp -.LP +.Pp +If both the +.Dv O_SYNC +and +.Dv O_DSYNC +flags are set, the effect is as if only the +.Dv O_SYNC +flag was set. +.Pp +If +.Fa path +refers to a STREAMS file, +.Fa oflag +may be constructed from +.Dv O_NONBLOCK +or +.Dv O_NODELAY +OR-ed with either +.Dv O_RDONLY , +.Dv O_WRONLY , +or +.Dv O_RDWR . +Other flag values are not applicable to STREAMS devices and have no effect on +them. +The values +.Dv O_NONBLOCK +and +.Dv O_NODELAY +affect the operation of STREAMS drivers and certain functions +.Po +see +.Xr read 2 , +.Xr getmsg 2 , +.Xr putmsg 2 , +and +.Xr write 2 +.Pc +applied to file descriptors associated with STREAMS files. +For STREAMS drivers, the implementation of +.Dv O_NONBLOCK +and +.Dv O_NODELAY +is device-specific. +.Pp +When +.Fn open +is invoked to open a named stream, and the +.Xr connld 7M +module has been pushed on the pipe, +.Fn open +blocks until the server process has issued an +.Dv I_RECVFD +.Xr ioctl 2 +.Po +see +.Xr streamio 7I +.Pc +to receive the file descriptor. +.Pp +If +.Fa path +names the manager side of a pseudo-terminal device, then it is unspecified +whether +.Fn open +locks the subsidiary side so that it cannot be opened. +Portable applications must call +.Xr unlockpt 3C +before opening the subsidiary side. +.Pp If the file is a regular file and the local file system is mounted with the -\fBnbmand\fR mount option, then a mandatory share reservation is automatically -obtained on the file. The share reservation is obtained as if \fBfcntl\fR(2) -were called with \fIcmd\fR \fBF_SHARE_NBMAND\fR and the \fBfshare_t\fR values -set as follows: -.sp -.ne 2 -.na -\fB\fBf_access\fR\fR -.ad -.RS 12n +.Cm nbmand +mount option, then a mandatory share reservation is automatically obtained on +the file. +The share reservation is obtained as if +.Xr fcntl 2 +were called with +.Fa cmd +.Dv F_SHARE_NBMAND +and the +.Vt fshare_t +values set as follows: +.Bl -tag -width Ds -offset Ds +.It Fa f_access Set to the type of read/write access for which the file is opened. -.RE - -.sp -.ne 2 -.na -\fB\fBf_deny\fR\fR -.ad -.RS 12n -\fBF_NODNY\fR -.RE - -.sp -.ne 2 -.na -\fB\fBf_id\fR\fR -.ad -.RS 12n -The file descriptor value returned from \fBopen()\fR. -.RE - -.sp -.LP -If \fIpath\fR is a symbolic link and \fBO_CREAT\fR and \fBO_EXCL\fR are set, -the link is not followed. -.sp -.LP -Certain flag values can be set following \fBopen()\fR as described in -\fBfcntl\fR(2). -.sp -.LP +.It Fa f_deny +.Dv F_NODNY +.It Fa f_id +The file descriptor value returned from +.Fn open . +.El +.Pp +If +.Fa path +is a symbolic link and +.Dv O_CREAT +and +.Dv O_EXCL +are set, the link is not followed. +.Pp +Certain flag values can be set following +.Fn open +as described in +.Xr fcntl 2 . +.Pp The largest value that can be represented correctly in an object of type -\fBoff_t\fR is established as the offset maximum in the open file description. -.SH RETURN VALUES -Upon successful completion, both \fBopen()\fR and \fBopenat()\fR functions open -the file and return a non-negative integer representing the lowest numbered -unused file descriptor. Otherwise, \fB\(mi1\fR is returned, \fBerrno\fR is set -to indicate the error, and no files are created or modified. -.SH ERRORS -The \fBopen()\fR and \fBopenat()\fR functions will fail if: -.sp -.ne 2 -.na -\fB\fBEACCES\fR\fR -.ad -.RS 16n -Search permission is denied on a component of the path prefix. -.sp -The file exists and the permissions specified by \fIoflag\fR are denied. -.sp -The file does not exist and write permission is denied for the parent directory -of the file to be created. -.sp -\fBO_TRUNC\fR is specified and write permission is denied. -.sp -The {\fBPRIV_FILE_DAC_SEARCH\fR} privilege allows processes to search -directories regardless of permission bits. The {\fBPRIV_FILE_DAC_WRITE\fR} -privilege allows processes to open files for writing regardless of permission -bits. See \fBprivileges\fR(5) for special considerations when opening files -owned by UID 0 for writing. The {\fBPRIV_FILE_DAC_READ\fR} privilege allows -processes to open files for reading regardless of permission bits. -.RE - -.sp -.ne 2 -.na -\fB\fBEAGAIN\fR\fR -.ad -.RS 16n -A mandatory share reservation could not be obtained because the desired access -conflicts with an existing \fBf_deny\fR share reservation. -.RE - -.sp -.ne 2 -.na -\fB\fBEDQUOT\fR\fR -.ad -.RS 16n -The file does not exist, \fBO_CREAT\fR is specified, and either the directory -where the new file entry is being placed cannot be extended because the user's -quota of disk blocks on that file system has been exhausted, or the user's -quota of inodes on the file system where the file is being created has been -exhausted. -.RE - -.sp -.ne 2 -.na -\fB\fBEEXIST\fR\fR -.ad -.RS 16n -The \fBO_CREAT\fR and \fBO_EXCL\fR flags are set and the named file exists. -.RE - -.sp -.ne 2 -.na -\fB\fBEILSEQ\fR\fR -.ad -.RS 16n -The \fIpath\fR argument includes non-UTF8 characters and the file system -accepts only file names where all characters are part of the UTF-8 character -codeset. -.RE - -.sp -.ne 2 -.na -\fB\fBEINTR\fR\fR -.ad -.RS 16n -A signal was caught during \fBopen()\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBEFAULT\fR\fR -.ad -.RS 16n -The \fIpath\fR argument points to an illegal address. -.RE - -.sp -.ne 2 -.na -\fB\fBEINVAL\fR\fR -.ad -.RS 16n -The system does not support synchronized or direct I/O for this file, or the -\fBO_XATTR\fR flag was supplied and the underlying file system does not support -extended file attributes. -.RE - -.sp -.ne 2 -.na -\fB\fBEIO\fR\fR -.ad -.RS 16n -The \fIpath\fR argument names a \fBSTREAMS\fR file and a hangup or error -occurred during the \fBopen()\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBEISDIR\fR\fR -.ad -.RS 16n -The named file is a directory and \fIoflag\fR includes \fBO_WRONLY\fR or -\fBO_RDWR\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBELOOP\fR\fR -.ad -.RS 16n -Too many symbolic links were encountered in resolving \fIpath\fR. -.sp -A loop exists in symbolic links encountered during resolution of the \fIpath\fR -argument. -.sp -The \fBO_NOFOLLOW\fR flag is set and the final component of path is a symbolic -link. -.RE - -.sp -.ne 2 -.na -\fB\fBEMFILE\fR\fR -.ad -.RS 16n -There are currently {\fBOPEN_MAX\fR} file descriptors open in the calling -process. -.RE - -.sp -.ne 2 -.na -\fB\fBEMLINK\fR\fR -.ad -.RS 16n -The \fBO_NOLINKS\fR flag is set and the named file has a link count greater -than 1. -.RE - -.sp -.ne 2 -.na -\fB\fBEMULTIHOP\fR\fR -.ad -.RS 16n -Components of \fIpath\fR require hopping to multiple remote machines and the -file system does not allow it. -.RE - -.sp -.ne 2 -.na -\fB\fBENAMETOOLONG\fR\fR -.ad -.RS 16n -The length of the \fIpath\fR argument exceeds {\fBPATH_MAX\fR} or a pathname -component is longer than {\fBNAME_MAX\fR}. -.RE - -.sp -.ne 2 -.na -\fB\fBENFILE\fR\fR -.ad -.RS 16n -The maximum allowable number of files is currently open in the system. -.RE - -.sp -.ne 2 -.na -\fB\fBENOENT\fR\fR -.ad -.RS 16n -The \fBO_CREAT\fR flag is not set and the named file does not exist; or the -\fBO_CREAT\fR flag is set and either the path prefix does not exist or the -\fIpath\fR argument points to an empty string. -.sp +.Vt off_t +is established as the offset maximum in the open file description. +.Sh RETURN VALUES The -.B O_CREAT +.Fn open and -.B O_DIRECTORY -flags were both set and -.I path -did not point to a file. -.RE - -.sp -.ne 2 -.na -.B ENOEXEC -.ad -.RS 16n -The \fBO_EXEC\fR flag is set and \fIpath\fR does not point to a regular -file. -.RE - -.sp -.ne 2 -.na -\fB\fBENOLINK\fR\fR -.ad -.RS 16n -The \fIpath\fR argument points to a remote machine, and the link to that -machine is no longer active. -.RE - -.sp -.ne 2 -.na -\fB\fBENOSR\fR\fR -.ad -.RS 16n -The \fIpath\fR argument names a STREAMS-based file and the system is unable to -allocate a STREAM. -.RE - -.sp -.ne 2 -.na -\fB\fBENOSPC\fR\fR -.ad -.RS 16n -The directory or file system that would contain the new file cannot be -expanded, the file does not exist, and \fBO_CREAT\fR is specified. -.RE - -.sp -.ne 2 -.na -\fB\fBENOSYS\fR\fR -.ad -.RS 16n -The device specified by \fIpath\fR does not support the open operation. -.RE - -.sp -.ne 2 -.na -\fB\fBENOTDIR\fR\fR -.ad -.RS 16n -A component of the path prefix is not a directory or a relative path was -supplied to \fBopenat()\fR, the \fBO_XATTR\fR flag was not supplied, and the -file descriptor does not refer to a directory. The \fBO_SEARCH\fR flag -was passed and \fIpath\fR does not refer to a directory. -.sp -The -.B O_DIRECTORY -flag was set and the file was not a directory. -.RE - -.sp -.ne 2 -.na -\fB\fBENXIO\fR\fR -.ad -.RS 16n -The \fBO_NONBLOCK\fR flag is set, the named file is a FIFO, the \fBO_WRONLY\fR -flag is set, and no process has the file open for reading; or the named file is -a character special or block special file and the device associated with this -special file does not exist or has been retired by the fault management -framework . -.RE - -.sp -.ne 2 -.na -\fB\fBEOPNOTSUPP\fR\fR -.ad -.RS 16n -An attempt was made to open a path that corresponds to a \fBAF_UNIX\fR socket. -.RE - -.sp -.ne 2 -.na -\fB\fBEOVERFLOW\fR\fR -.ad -.RS 16n -The named file is a regular file and either \fBO_LARGEFILE\fR is not set and -the size of the file cannot be represented correctly in an object of type -\fBoff_t\fR or \fBO_LARGEFILE\fR is set and the size of the file cannot be -represented correctly in an object of type \fBoff64_t\fR. -.RE - -.sp -.ne 2 -.na -\fB\fBEROFS\fR\fR -.ad -.RS 16n -The named file resides on a read-only file system and either \fBO_WRONLY\fR, -\fBO_RDWR\fR, \fBO_CREAT\fR (if file does not exist), or \fBO_TRUNC\fR is set -in the \fIoflag\fR argument. -.RE - -.sp -.LP -The \fBopenat()\fR function will fail if: -.sp -.ne 2 -.na -\fB\fBEBADF\fR\fR -.ad -.RS 9n -The \fIfildes\fR argument is not a valid open file descriptor or is not -\fBAT_FTCWD\fR. -.RE - -.sp -.LP -The \fBopen()\fR function may fail if: -.sp -.ne 2 -.na -\fB\fBEAGAIN\fR\fR -.ad -.RS 16n -The \fIpath\fR argument names the slave side of a pseudo-terminal device that -is locked. -.RE - -.sp -.ne 2 -.na -\fB\fBEINVAL\fR\fR -.ad -.RS 16n -The value of the \fIoflag\fR argument is not valid. -.RE - -.sp -.ne 2 -.na -\fB\fBENAMETOOLONG\fR\fR -.ad -.RS 16n -Pathname resolution of a symbolic link produced an intermediate result whose -length exceeds {\fBPATH_MAX\fR}. -.RE - -.sp -.ne 2 -.na -\fB\fBENOMEM\fR\fR -.ad -.RS 16n -The \fIpath\fR argument names a \fBSTREAMS\fR file and the system is unable to -allocate resources. -.RE - -.sp -.ne 2 -.na -\fB\fBETXTBSY\fR\fR -.ad -.RS 16n -The file is a pure procedure (shared text) file that is being executed and -\fIoflag\fR is \fBO_WRONLY\fR or \fBO_RDWR\fR. -.RE - -.SH EXAMPLES -\fBExample 1 \fROpen a file for writing by the owner. -.sp -.LP -The following example opens the file \fB/tmp/file\fR, either by creating it if -it does not already exist, or by truncating its length to 0 if it does exist. +.Fn openat +functions open the file and, if successful, return a non-negative integer +representing the lowest numbered unused file descriptor; otherwise the +value +.Sy -1 +is returned and the global variable +.Va errno +is set to indicate the error and no files are created or modified. +.Sh EXAMPLES +.Sy Example 1 +Open a file for writing by the owner. +.Pp +The following example opens the file +.Pa /tmp/file , +either by creating it if it does not already exist, or by truncating its length +to +.Sy 0 +if it does exist. If the call creates a new file, the access permission bits in the file mode of the file are set to permit reading and writing by the owner, and to permit reading only by group members and others. - -.sp -.LP -If the call to \fBopen()\fR is successful, the file is opened for writing. - -.sp -.in +2 -.nf +.Pp +If the call to +.Fn open +is successful, the file is opened for writing. +.Bd -literal -offset Ds #include <fcntl.h> \&... int fd; @@ -928,98 +635,361 @@ char *filename = "/tmp/file"; \&... fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode); \&... -.fi -.in -2 - -.LP -\fBExample 2 \fROpen a file using an existence check. -.sp -.LP -The following example uses the \fBopen()\fR function to try to create the -\fBLOCKFILE\fR file and open it for writing. Since the \fBopen()\fR function -specifies the \fBO_EXCL\fR flag, the call fails if the file already exists. In -that case, the application assumes that someone else is updating the password -file and exits. - -.sp -.in +2 -.nf +.Ed +.Pp +.Sy Example 2 +Open a file using an existence check. +.Pp +The following example uses the +.Fn open +function to try to create the +.Dv LOCKFILE +file and open it for writing. +Since the +.Fn open +function specifies the +.Dv O_EXCL +flag, the call fails if the file already exists. +In that case, the application assumes that someone else is updating the +password file and exits. +.Bd -literal -offset Ds #include <fcntl.h> #include <stdio.h> #include <stdlib.h> +#include <err.h> +\&... #define LOCKFILE "/etc/ptmp" \&... int pfd; /* Integer for file descriptor returned by open() call. */ \&... if ((pfd = open(LOCKFILE, O_WRONLY | O_CREAT | O_EXCL, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) -{ - fprintf(stderr, "Cannot open /etc/ptmp. Try again later.\en"); - exit(1); + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) { + err(1, "Cannot open %s. Try again later.", LOCKFILE); } \&... -.fi -.in -2 - -.LP -\fBExample 3 \fROpen a file for writing. -.sp -.LP +.Ed +.Pp +.Sy Example 3 +Open a file for writing. +.Pp The following example opens a file for writing, creating the file if it does -not already exist. If the file does exist, the system truncates the file to -zero bytes. - -.sp -.in +2 -.nf +not already exist. +If the file does exist, the system truncates the file to zero bytes. +.Bd -literal -offset Ds #include <fcntl.h> #include <stdio.h> #include <stdlib.h> -#define LOCKFILE "/etc/ptmp" +#include <err.h> \&... int pfd; char filename[PATH_MAX+1]; \&... if ((pfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) -{ - perror("Cannot open output file\en"); exit(1); + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) { + err(1, "Cannot open output file"); } \&... -.fi -.in -2 - -.SH USAGE -The \fBopen()\fR function has a transitional interface for 64-bit file offsets. -See \fBlf64\fR(5). Note that using \fBopen64()\fR is equivalent to using -\fBopen()\fR with \fBO_LARGEFILE\fR set in \fIoflag\fR. -.SH ATTRIBUTES -See \fBattributes\fR(5) for descriptions of the following attributes: -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -Interface Stability Committed -_ -MT-Level Async-Signal-Safe -_ -Standard For \fBopen()\fR, see \fBstandards\fR(5). -.TE - -.SH SEE ALSO -\fBIntro\fR(2), \fBchmod\fR(2), \fBclose\fR(2), \fBcreat\fR(2), \fBdup\fR(2), -\fBexec\fR(2), \fBfcntl\fR(2), \fBgetmsg\fR(2), \fBgetrlimit\fR(2), -\fBlseek\fR(2), \fBputmsg\fR(2), \fBread\fR(2), \fBstat\fR(2), \fBumask\fR(2), -\fBwrite\fR(2), \fBattropen\fR(3C), \fBdirectio\fR(3C), -\fBfcntl.h\fR(3HEAD), \fBstat.h\fR(3HEAD), -\fBunlockpt\fR(3C), \fBattributes\fR(5), \fBlf64\fR(5), \fBprivileges\fR(5), -\fBstandards\fR(5), \fBconnld\fR(7M), \fBstreamio\fR(7I) -.SH NOTES -Hierarchical Storage Management (HSM) file systems can sometimes cause long -delays when opening a file, since HSM files must be recalled from secondary -storage. +.Ed +.Sh ERRORS +The +.Fn open +and +.Fn openat +functions will fail if: +.Bl -tag -width Er +.It Er EACCES +Search permission is denied on a component of the path prefix. +.Pp +The file exists and the permissions specified by +.Fa oflag +are denied. +.Pp +The file does not exist and write permission is denied for the parent directory +of the file to be created. +.Pp +.Dv O_TRUNC +is specified and write permission is denied. +.Pp +The +.Brq Dv PRIV_FILE_DAC_SEARCH +privilege allows processes to search directories regardless of permission bits. +The +.Brq Dv PRIV_FILE_DAC_WRITE +privilege allows processes to open files for writing regardless of permission +bits. +See +.Xr privileges 5 for special considerations when opening files owned by user ID +.Sy 0 +for writing. +The +.Brq Dv PRIV_FILE_DAC_READ +privilege allows +processes to open files for reading regardless of permission bits. +.It Er EAGAIN +A mandatory share reservation could not be obtained because the desired access +conflicts with an existing +.Fa f_deny +share reservation +.Po +see +.Xr fcntl 2 +.Pc . +.It Er EDQUOT +The file does not exist, +.Dv O_CREAT +is specified, and either the directory where the new file entry is being placed +cannot be extended because the user's quota of disk blocks on that file system +has been exhausted, or the user's quota of inodes on the file system where the +file is being created has been exhausted. +.It Er EEXIST +The +.Dv O_CREAT +and +.Dv O_EXCL +flags are set and the named file already exists. +.It Er EILSEQ +The +.Fa path +argument includes bytes that are not valid UTF-8 characters, and the file +system accepts only file names where all characters are part of the UTF-8 +character codeset. +.It Er EINTR +A signal was caught during +.Fn open . +.It Er EFAULT +The +.Fa path +argument points to an illegal address. +.It Er EINVAL +Either the system does not support synchronized or direct I/O for this file, or +the +.Dv O_XATTR +flag was supplied and the underlying file system does not support extended file +attributes. +.It Er EIO +The +.Fa path +argument names a STREAMS file and a hangup or error occurred during the +.Fn open . +.It Er EISDIR +The named file is a directory and +.Fa oflag +includes +.Dv O_WRONLY +or +.Dv O_RDWR . +.It Er ELOOP +Too many symbolic links were encountered in resolving +.Fa path . +.Pp +A loop exists in symbolic links encountered during resolution of the +.Fa path +argument. +.Pp +The +.Dv O_NOFOLLOW +flag is set and the final component of path is a symbolic link. +.It Er EMFILE +There are currently +.Brq Dv OPEN_MAX +file descriptors open in the calling process. +.It Er EMLINK +The +.Dv O_NOLINKS +flag is set and the named file has a link count greater than +.Sy 1 . +.It Er EMULTIHOP +Components of +.Fa path +require hopping to multiple remote machines and the file system does not allow +it. +.It Er ENAMETOOLONG +The length of the +.Fa path +argument exceeds +.Brq Dv PATH_MAX +or a pathname component is longer than +.Brq Dv NAME_MAX . +.It Er ENFILE +The maximum allowable number of files is currently open in the system. +.It Er ENOENT +The +.Dv O_CREAT +flag is not set and the named file does not exist; or the +.Dv O_CREAT +flag is set and either the path prefix does not exist or the +.Fa path +argument points to an empty string. +.Pp +The +.Dv O_CREAT +and +.Dv O_DIRECTORY +flags were both set and +.Fa path +did not point to a file. +.It Er ENOEXEC +The +.Dv O_EXEC +flag is set and +.Fa path +does not point to a regular file. +.It Er ENOLINK +The +.Fa path +argument points to a remote machine, and the link to that machine is no longer +active. +.It Er ENOSR +Th +.Fa path +argument names a STREAMS-based file and the system is unable to allocate a +STREAM. +.It Er ENOSPC +The directory or file system that would contain the new file cannot be +expanded, the file does not exist, and +.Dv O_CREAT +is specified. +.It Er ENOSYS +The device specified by +.Fa path +does not support the open operation. +.It Er ENOTDIR +A component of the path prefix is not a directory or a relative path was +supplied to +.Fn openat , +the +.Dv O_XATTR +flag was not supplied, and the file descriptor does not refer to a directory. +The +.Dv O_SEARCH +flag was passed and +.Fa path +does not refer to a directory. +.Pp +The +.Dv O_DIRECTORY +flag was set and the file was not a directory. +.It Er ENXIO +The +.Dv O_NONBLOCK +flag is set, the named file is a FIFO, the +.Dv O_WRONLY +flag is set, and no process has the file open for reading; or the named file is +a character special or block special file and the device associated with this +special file does not exist or has been retired by the fault management +framework. +.It Er EOPNOTSUPP +An attempt was made to open a path that corresponds to an +.Dv AF_UNIX +socket. +.It Er EOVERFLOW +The named file is a regular file and either +.Dv O_LARGEFILE +is not set and the size of the file cannot be represented correctly in an +object of type +.Vt off_t +or +.Dv O_LARGEFILE +is set and the size of the file cannot be represented correctly in an object of +type +.Vt off64_t . +.It Er EROFS +The named file resides on a read-only file system and either +.Dv O_WRONLY , +.Dv O_RDWR , +.Dv O_CREAT +(if file does not exist), or +.Dv O_TRUNC +is set in the +.Fa oflag +argument. +.El +.Pp +The +.Fn openat +function will fail if: +.Bl -tag -width Er +.It Er EBADF +The +.Fa fildes +argument is not a valid open file descriptor or is not +.Dv AT_FTCWD . +.El +.Pp +The +.Fn open +function may fail if: +.Bl -tag -width Er +.It Er EAGAIN +The +.Fa path +argument names the subsidiary side of a pseudo-terminal device that is locked. +.It Er EINVAL +The value of the +.Fa oflag +argument is not valid. +.It Er ENAMETOOLONG +Pathname resolution of a symbolic link produced an intermediate result whose +length exceeds +.Brq Dv PATH_MAX . +.It Er ENOMEM +The +.Fa path +argument names a STREAMS file and the system is unable to allocate resources. +.It Er ETXTBSY +The file is a pure procedure (shared text) file that is being executed and +.Fa oflag +is +.Dv O_WRONLY +or +.Dv O_RDWR . +.El +.Sh USAGE +The +.Fn open +function has a transitional interface for 64-bit file offsets. +See +.Xr lf64 5 . +Note that using +.Fn open64 +is equivalent to using +.Fn open with +.Dv O_LARGEFILE +set in +.Fa oflag . +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT LEVEL +.Sy Async-Signal-Safe +.Sh SEE ALSO +.Xr chmod 2 , +.Xr close 2 , +.Xr creat 2 , +.Xr dup 2 , +.Xr exec 2 , +.Xr fcntl 2 , +.Xr getmsg 2 , +.Xr getrlimit 2 , +.Xr Intro 2 , +.Xr lseek 2 , +.Xr putmsg 2 , +.Xr read 2 , +.Xr stat 2 , +.Xr umask 2 , +.Xr write 2 , +.Xr attropen 3C , +.Xr directio 3C , +.Xr unlockpt 3C , +.Xr fcntl.h 3HEAD , +.Xr stat.h 3HEAD , +.Xr attributes 5 , +.Xr lf64 5 , +.Xr privileges 5 , +.Xr standards 5 , +.Xr streamio 7I , +.Xr connld 7M +.Sh NOTES +Hierarchical Storage Management +.Pq HSM +file systems can sometimes cause long delays when opening a file, since HSM +files must be recalled from secondary storage. diff --git a/usr/src/man/man3c/grantpt.3c b/usr/src/man/man3c/grantpt.3c index 7e523af80b..154a5a07f5 100644 --- a/usr/src/man/man3c/grantpt.3c +++ b/usr/src/man/man3c/grantpt.3c @@ -43,88 +43,76 @@ .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1994, X/Open Company Limited. All Rights Reserved. .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright 2022 Oxide Computer Company .\" -.TH GRANTPT 3C "Aug 14, 2006" -.SH NAME -grantpt \- grant access to the slave pseudo-terminal device -.SH SYNOPSIS -.LP -.nf -#include <stdlib.h> - -\fBint\fR \fBgrantpt\fR(\fBint\fR \fIfildes\fR); -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBgrantpt()\fR function changes the mode and ownership of the slave -pseudo-terminal device associated with its master pseudo-terminal counterpart. -\fIfildes\fR is the file descriptor returned from a successful open of the -master pseudo-terminal device. The user ID of the slave is set to the real UID -of the calling process and the group ID is set to a reserved group. The -permission mode of the slave pseudo-terminal is set to readable and writable by -the owner and writable by the group. -.SH RETURN VALUES -.sp -.LP -Upon successful completion, \fBgrantpt()\fR returns \fB0\fR. Otherwise, it -returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error. -.SH ERRORS -.sp -.LP -The \fBgrantpt()\fR function may fail if: -.sp -.ne 2 -.na -\fB\fBEBADF\fR\fR -.ad -.RS 10n -The \fIfildes\fR argument is not a valid open file descriptor. -.RE - -.sp -.ne 2 -.na -\fB\fBEINVAL\fR\fR -.ad -.RS 10n -The \fIfildes\fR argument is not associated with a master pseudo-terminal +.Dd February 5, 2022 +.Dt GRANTPT 3C +.Os +.Sh NAME +.Nm grantpt +.Nd grant access to the subsidiary device of a pseudo-terminal +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fo grantpt +.Fa "int fildes" +.Fc +.Sh DESCRIPTION +The +.Fn grantpt +function changes the mode and ownership of the pseudo-terminal subsidiary +device associated with its pseudo-terminal manager counterpart. +.Pp +The +.Fa fildes +argument is the file descriptor returned from a successful +.Xr open 2 +of the pseudo-terminal manager device; e.g., by calling +.Xr posix_openpt 3C +or by performing an +.Xr open 2 +of the +.Xr ptm 7D device. -.RE - -.sp -.ne 2 -.na -\fB\fBEACCES\fR\fR -.ad -.RS 10n -The corresponding slave pseudo-terminal device could not be accessed. -.RE - -.SH ATTRIBUTES -.sp -.LP -See \fBattributes\fR(5) for descriptions of the following attributes: -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -Interface Stability Standard -_ -MT-Level Safe -.TE - -.SH SEE ALSO -.sp -.LP -\fBopen\fR(2), \fBptsname\fR(3C), \fBunlockpt\fR(3C), \fBattributes\fR(5), -\fBstandards\fR(5) -.sp -.LP -\fISTREAMS Programming Guide\fR +.Pp +The user ID owner of the subsidiary device is set to the real user ID of the +calling process. +The group ID owner is set to a reserved group. +.Pp +The permission mode of the subsidiary device is set to be readable and writable +by the owner, and writable by the group. +.Sh RETURN VALUES +.Rv -std grantpt +.Sh EXAMPLES +See +.Xr posix_openpt 3C +for an example that includes a call to +.Fn grantpt . +.Sh ERRORS +The +.Fn grantpt +function may fail if: +.Bl -tag -width Er +.It Er EBADF +The +.Fa fildes +argument is not a valid open file descriptor. +.It Er EINVAL +The +.Fa fildes +argument is not associated with a pseudo-terminal manager device. +.It Er EACCES +The corresponding pseudo-terminal subsidiary device could not be accessed. +.El +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT LEVEL +.Sy Safe +.Sh SEE ALSO +.Xr open 2 , +.Xr posix_openpt 3C , +.Xr ptsname 3C , +.Xr unlockpt 3C , +.Xr attributes 5 , +.Xr standards 5 , +.Xr ptm 7D diff --git a/usr/src/man/man3c/posix_openpt.3c b/usr/src/man/man3c/posix_openpt.3c index 16193b89f3..b009dd6e17 100644 --- a/usr/src/man/man3c/posix_openpt.3c +++ b/usr/src/man/man3c/posix_openpt.3c @@ -42,160 +42,142 @@ .\" .\" Copyright (c) 2001, The IEEE and The Open Group. All Rights Reserved. .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright 2022 Oxide Computer Company .\" -.TH POSIX_OPENPT 3C "June 18, 2021" -.SH NAME -posix_openpt \- open a pseudo terminal device -.SH SYNOPSIS -.nf -#include <stdlib.h> -#include <fcntl.h> - -\fBint\fR \fBposix_openpt\fR(\fBint\fR \fIoflag\fR); -.fi - -.SH DESCRIPTION -The \fBposix_openpt()\fR function establishes a connection between a master -device for a pseudo-terminal and a file descriptor. The file descriptor is used -by other I/O functions that refer to that pseudo-terminal. -.sp -.LP +.Dd February 5, 2022 +.Dt POSIX_OPENPT 3C +.Os +.Sh NAME +.Nm posix_openpt +.Nd open a pseudo-terminal manager device +.Sh SYNOPSIS +.In stdlib.h +.In fcntl.h +.Ft int +.Fo posix_openpt +.Fa "int oflag" +.Fc +.Sh DESCRIPTION +The +.Fn posix_openpt +function establishes a connection between a manager device for a +pseudo-terminal and a file descriptor. +The file descriptor is used by other I/O functions that refer to that +pseudo-terminal. +.Pp The file status flags and file access modes of the open file description are -set according to the value of \fIoflag\fR. -.sp -.LP -Values for \fIoflag\fR are constructed by a bitwise-inclusive OR of flags from -the following list, defined in <\fBfcntl.h\fR>. -.sp -.ne 2 -.na -\fB\fBO_RDWR\fR\fR -.ad -.RS 12n +set according to the value of +.Fa oflag . +.Pp +Values for +.Fa oflag +are constructed by a bitwise-inclusive OR of flags from +the following list, defined in +.Xr fcntl.h 3HEAD : +.Bl -tag -width Ds +.It Dv O_RDWR Open for reading and writing. -.RE - -.sp -.ne 2 -.na -\fB\fBO_NOCTTY\fR\fR -.ad -.RS 12n -If set, \fBposix_openpt()\fR does not cause the terminal device to become the -controlling terminal for the process. -.RE - -.sp -.LP -The behavior of other values for the \fIoflag\fR argument is unspecified. -.SH RETURN VALUES -Upon successful completion, the \fBposix_openpt()\fR function opens a master -pseudo-terminal device and returns a non-negative integer representing the -lowest numbered unused file descriptor. Otherwise, -1 is returned and -\fBerrno\fR is set to indicate the error. -.SH ERRORS -The \fBposix_openpt()\fR function will fail if: -.sp -.ne 2 -.na -\fB\fBEMFILE\fR\fR -.ad -.RS 10n -{\fBOPEN_MAX\fR} file descriptors are currently open in the calling process. -.RE - -.sp -.ne 2 -.na -\fB\fBENFILE\fR\fR -.ad -.RS 10n -The maximum allowable number of files is currently open in the system. -.RE - -.sp -.LP -The \fBposix_openpt()\fR function may fail if: -.sp -.ne 2 -.na -\fB\fBEINVAL\fR\fR -.ad -.RS 10n -The value of \fIoflag\fR is not valid. -.RE - -.sp -.ne 2 -.na -\fB\fBEAGAIN\fR\fR -.ad -.RS 10n -Out of pseudo-terminal resources. -.RE - -.sp -.ne 2 -.na -\fB\fBENOSR\fR\fR -.ad -.RS 10n -Out of STREAMS resources. -.RE - -.SH EXAMPLES -\fBExample 1 \fROpen a pseudo-terminal. -.sp -.LP -The following example opens a pseudo-terminal and returns the name of the slave -device and a file descriptor. - -.sp -.in +2 -.nf +.It Dv O_NOCTTY +If set, +.Fn posix_openpt +does not cause the terminal device to become the controlling terminal for the +process. +.El +.Pp +The behavior of other values for the +.Fa oflag +argument is unspecified. +.Sh RETURN VALUES +The +.Fn posix_getopt +function opens a manager pseudo-terminal device and, if successful, returns a +non-negative integer representing the lowest numbered unused file descriptor ; +otherwise, the value +.Sy -1 +is returned and the global variable +.Va errno +is set to indicate the error. +.Sh EXAMPLES +.Sy Example 1 +Open a pseudo-terminal. +.Pp +The following example opens a pseudo-terminal and returns the name of the +subsidiary device and a file descriptor. +.Bd -literal -offset Ds #include <fcntl.h> #include <stdio.h> - -int masterfd, slavefd; -char *slavedevice; - -masterfd = posix_openpt(O_RDWR|O_NOCTTY); - -if (masterfd == -1 - || grantpt (masterfd) == -1 - || unlockpt (masterfd) == -1 - || (slavedevice = ptsname (masterfd)) == NULL) - return -1; - -printf("slave device is: %s\en", slavedevice); - -slavefd = open(slave, O_RDWR|O_NOCTTY); -if (slavefd < 0) - return -1; -.fi -.in -2 - -.SH USAGE -This function provides a method for portably obtaining a file descriptor of a -master terminal device for a pseudo-terminal. The \fBgrantpt\fR(3C) and -\fBptsname\fR(3C) functions can be used to manipulate mode and ownership -permissions and to obtain the name of the slave device, respectively. -.SH ATTRIBUTES -See \fBattributes\fR(5) for descriptions of the following attributes: -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -Interface Stability Standard -_ -MT-Level MT-Safe -.TE - -.SH SEE ALSO -\fBopen\fR(2), \fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBunlockpt\fR(3C), -\fBattributes\fR(5), \fBstandards\fR(5) +#include <err.h> + +int managerfd, subsidiaryfd; +char *subsidiarydevice; + +if ((managerfd = posix_openpt(O_RDWR|O_NOCTTY)) < 0) { + err(1, "opening pseudo-terminal manager"); +} + +if (grantpt(managerfd) != 0 || + unlockpt(managerfd) != 0 || + (subsidiarydevice = ptsname(managerfd)) == NULL) { + (void) close(managerfd); + err(1, "locating pseudo-terminal subsidiary"); +} + +printf("subsidiary device is: %s\en", subsidiarydevice); + +if ((subsidiaryfd = open(subsidiary, O_RDWR|O_NOCTTY)) < 0) { + err(1, "opening pseudo-terminal subsidiary"); +} +.Ed +.Sh ERRORS +The +.Fn posix_openpt +function will fail if: +.Bl -tag -width Er +.It Er EMFILE +.Brq Dv OPEN_MAX +file descriptors are currently open in the calling process. +.It Er ENFILE +The maximum allowable number of files is currently open in the system. +.El +.Pp +The +.Fn posix_openpt +function may fail if: +.Bl -tag -width Er +.It Er EINVAL +The value of +.Fa oflag +is not valid. +.It Er EAGAIN +The system has run out of pseudo-terminal resources. +.It Er ENOSR +The system has run out of STREAMS resources. +.El +.Sh USAGE +This function provides a portable method for obtaining the file descriptor of a +manager terminal device for a pseudo-terminal, as opposed to using +.Xr open 2 +on the +.Xr ptm 7D +device which is system-specific. +.Pp +The +.Xr grantpt 3C +function can be used to manipulate the mode and ownership permissions +of the subsidiary device. +The +.Xr ptsname 3C +function can be used to obtain the name of the subsidiary device. +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr open 2 , +.Xr grantpt 3C , +.Xr ptsname 3C , +.Xr unlockpt 3C , +.Xr attributes 5 , +.Xr standards 5 , +.Xr ptm 7D , +.Xr pts 7D diff --git a/usr/src/man/man3c/ptsname.3c b/usr/src/man/man3c/ptsname.3c index 8fa25e2ea6..264a3dcc90 100644 --- a/usr/src/man/man3c/ptsname.3c +++ b/usr/src/man/man3c/ptsname.3c @@ -43,59 +43,72 @@ .\" Copyright 1989 AT&T .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright 2022 Oxide Computer Company .\" -.TH PTSNAME 3C "Aug 14, 2002" -.SH NAME -ptsname \- get name of the slave pseudo-terminal device -.SH SYNOPSIS -.LP -.nf -#include <stdlib.h> - -\fBchar *\fR\fBptsname\fR(\fBint\fR \fIfildes\fR); -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBptsname()\fR function returns the name of the slave pseudo-terminal -device associated with a master pseudo-terminal device. \fIfildes\fR is a file -descriptor returned from a successful open of the master device. -\fBptsname()\fR returns a pointer to a string containing the null-terminated -path name of the slave device of the form \fB/dev/pts/N\fR, where \fBN\fR is a -non-negative integer. -.SH RETURN VALUES -.sp -.LP -Upon successful completion, the function \fBptsname()\fR returns a pointer to a -string which is the name of the pseudo-terminal slave device. This value points -to a static data area that is overwritten by each call to \fBptsname()\fR. Upon -failure, \fBptsname()\fR returns \fINULL\fR. This could occur if \fIfildes\fR -is an invalid file descriptor or if the slave device name does not exist in -the file system. -.SH ATTRIBUTES -.sp -.LP -See \fBattributes\fR(5) for descriptions of the following attributes: -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -Interface Stability Standard -_ -MT-Level Safe -.TE - -.SH SEE ALSO -.sp -.LP -\fBopen\fR(2), \fBgrantpt\fR(3C), \fBttyname\fR(3C), \fBunlockpt\fR(3C), -\fBattributes\fR(5), \fBstandards\fR(5) -.sp -.LP -\fISTREAMS Programming Guide\fR +.Dd February 5, 2022 +.Dt PTSNAME 3C +.Os +.Sh NAME +.Nm ptsname +.Nd get the name of the subsidiary device of a pseudo-terminal +.Sh SYNOPSIS +.In stdlib.h +.Ft char * +.Fo ptsname +.Fa "int fildes" +.Fc +.Sh DESCRIPTION +The +.Fn ptsname +function returns the name of the pseudo-terminal subsidiary device associated +with a pseudo-terminal manager device. +The +.Fa fildes +argument is a file descriptor returned from a successful open of the +pseudo-terminal manager device; e.g., by calling +.Xr posix_openpt 3C +or by performing an +.Xr open 2 +of the +.Xr ptm 7D +device. +.Pp +The +.Fn ptsname +function returns a pointer to a string containing the null-terminated +path name of the subsidiary device. +This string is of the form +.Pa /dev/pts/N , +where +.Sy N +is a non-negative integer. +.Sh RETURN VALUES +If successful, the +.Fn ptsname +function returns a pointer to a string which is the name of the pseudo-terminal +subsidiary device. +This value points to a static data area that is overwritten by each call to +.Fn ptsname . +.Pp +Upon failure, +.Fn ptsname +returns +.Dv NULL . +This could occur if +.Fa fildes +is an invalid file descriptor or if the subsidiary device name does not exist +in the file system. +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT LEVEL +.Sy Safe +.Sh SEE ALSO +.Xr open 2 , +.Xr grantpt 3C , +.Xr posix_openpt 3C , +.Xr ttyname 3C , +.Xr unlockpt 3C , +.Xr attributes 5 , +.Xr standards 5 , +.Xr ptm 7D , +.Xr pts 7D diff --git a/usr/src/man/man3c/unlockpt.3c b/usr/src/man/man3c/unlockpt.3c index 598a56717d..865c217e32 100644 --- a/usr/src/man/man3c/unlockpt.3c +++ b/usr/src/man/man3c/unlockpt.3c @@ -43,78 +43,69 @@ .\" Copyright 1989 AT&T .\" Copyright (c) 1997, The Open Group. All Rights Reserved. .\" Portions Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright 2022 Oxide Computer Company .\" -.TH UNLOCKPT 3C "Aug 14, 2002" -.SH NAME -unlockpt \- unlock a pseudo-terminal master/slave pair -.SH SYNOPSIS -.LP -.nf -#include <stdlib.h> - -\fBint\fR \fBunlockpt\fR(\fBint\fR \fIfildes\fR); -.fi - -.SH DESCRIPTION -.sp -.LP -The \fBunlockpt()\fR function unlocks the slave pseudo-terminal device -associated with the master to which \fIfildes\fR refers. -.sp -.LP -Portable applications must call \fBunlockpt()\fR before opening the slave side -of a pseudo-terminal device. -.SH RETURN VALUES -.sp -.LP -Upon successful completion, \fBunlockpt()\fR returns \fB0\fR. Otherwise, it -returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error. -.SH ERRORS -.sp -.LP -The \fBunlockpt()\fR function may fail if: -.sp -.ne 2 -.na -\fB\fBEBADF\fR\fR -.ad -.RS 10n -The \fIfildes\fR argument is not a file descriptor open for writing. -.RE - -.sp -.ne 2 -.na -\fB\fBEINVAL\fR\fR -.ad -.RS 10n -The \fIfildes\fR argument is not associated with a master pseudo-terminal -device. -.RE - -.SH ATTRIBUTES -.sp -.LP -See \fBattributes\fR(5) for descriptions of the following attributes: -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ -Interface Stability Standard -_ -MT-Level Safe -.TE - -.SH SEE ALSO -.sp -.LP -\fBopen\fR(2), \fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBattributes\fR(5), -\fBstandards\fR(5) -.sp -.LP -\fISTREAMS Programming Guide\fR +.Dd February 5, 2022 +.Dt UNLOCKPT 3C +.Os +.Sh NAME +.Nm unlockpt +.Nd unlock a pseudo-terminal device pair +.Sh SYNOPSIS +.In stdlib.h +.Ft int +.Fo unlockpt +.Fa "int fildes" +.Fc +.Sh DESCRIPTION +When a pseudo-terminal manager device is opened, whether through +.Xr posix_openpt 3C +or +.Xr open 2 +on a +.Xr ptm 7D +device, the subsidiary device begins operation in a locked state. +The +.Fn unlockpt +function unlocks the pseudo-terminal subsidiary device associated with the +manager device to which +.Fa fildes +refers. +.Pp +Portable applications must call +.Fn unlockpt +before opening the pseudo-terminal subsidiary device. +.Sh RETURN VALUES +.Rv -std unlockpt +.Sh EXAMPLES +See +.Xr posix_openpt 3C +for an example that includes a call to +.Fn unlockpt . +.Sh ERRORS +The +.Fn unlockpt +function may fail if: +.Bl -tag -width Er +.It Er EBADF +The +.Fa fildes +argument is not a file descriptor open for writing. +.It Er EINVAL +EINVAL +The +.Fa fildes +argument is not associated with a pseudo-terminal manager device. +.El +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT LEVEL +.Sy Safe +.Sh SEE ALSO +.Xr open 2 , +.Xr grantpt 3C , +.Xr posix_openpt 3C , +.Xr ptsname 3C , +.Xr attributes 5 , +.Xr standards 5 , +.Xr ptm 7D diff --git a/usr/src/man/man3utempter/utempter_add_record.3utempter b/usr/src/man/man3utempter/utempter_add_record.3utempter index da6cbb7211..21f0f44a94 100644 --- a/usr/src/man/man3utempter/utempter_add_record.3utempter +++ b/usr/src/man/man3utempter/utempter_add_record.3utempter @@ -23,7 +23,7 @@ .\" SUCH DAMAGE. .\" .\" -.Dd May 5, 2020 +.Dd February 5, 2022 .Dt UTEMPTER_ADD_RECORD 3UTEMPTER .Os .Sh NAME @@ -67,7 +67,7 @@ and .Fn addToUtmp functions add a login record to the .Xr utmpx 4 -database for the TTY belonging to the pseudo-terminal master file descriptor +database for the TTY belonging to the pseudo-terminal manager file descriptor .Fa fd , using the username corresponding with the real user ID of the calling process and the optional hostname @@ -83,7 +83,7 @@ The and .Fn removeLineFromUtmp functions mark the login session as being closed for the TTY belonging -to the pseudo-terminal master file descriptor +to the pseudo-terminal manager file descriptor .Fa fd . .Pp The diff --git a/usr/src/man/man7d/Makefile b/usr/src/man/man7d/Makefile index af38c7a9bd..78b9601e29 100644 --- a/usr/src/man/man7d/Makefile +++ b/usr/src/man/man7d/Makefile @@ -16,7 +16,7 @@ # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> # Copyright 2018 Nexenta Systems, Inc. # Copyright 2020 Peter Tribble -# Copyright 2021 Oxide Computer Company +# Copyright 2022 Oxide Computer Company # include $(SRC)/Makefile.master @@ -105,7 +105,6 @@ _MANFILES= aac.7d \ poll.7d \ profile.7d \ ptm.7d \ - pts.7d \ pty.7d \ qlc.7d \ ramdisk.7d \ @@ -256,6 +255,7 @@ _MANLINKS= 1394.7d \ firewire.7d \ kmem.7d \ lo0.7d \ + pts.7d \ ticots.7d \ ticotsord.7d \ urandom.7d \ @@ -279,6 +279,8 @@ firewire.7d := LINKSRC = ieee1394.7d lo0.7d := LINKSRC = ipnet.7d +pts.7d := LINKSRC = ptm.7d + allkmem.7d := LINKSRC = mem.7d kmem.7d := LINKSRC = mem.7d diff --git a/usr/src/man/man7d/ptm.7d b/usr/src/man/man7d/ptm.7d index 83c7830293..adf66469bc 100644 --- a/usr/src/man/man7d/ptm.7d +++ b/usr/src/man/man7d/ptm.7d @@ -4,89 +4,255 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH PTM 7D "Feb 5, 1997" -.SH NAME -ptm \- STREAMS pseudo-tty master driver -.SH DESCRIPTION -.sp -.LP -The pseudo-tty subsystem simulates a terminal connection, where the master side -represents the terminal and the slave represents the user process's special -device end point. In order to use the pseudo-tty subsystem, a node for the -master side driver \fB/dev/ptmx\fR and \fBN\fR number of nodes for the slave -driver must be installed. See \fBpts\fR(7D). The master device is set up as a -cloned device where its major device number is the major for the clone device -and its minor device number is the major for the \fBptm\fR driver. There are no -nodes in the file system for master devices. The master pseudo driver is opened -using the \fBopen\fR(2) system call with \fB/dev/ptmx\fR as the device -parameter. The clone open finds the next available minor device for the -\fBptm\fR major device. -.sp -.LP -A master device is available only if it and its corresponding slave device are -not already open. When the master device is opened, the corresponding slave -device is automatically locked out. Only one open is allowed on a master -device. Multiple opens are allowed on the slave device. After both the master -and slave have been opened, the user has two file descriptors which are the end -points of a full duplex connection composed of two streams which are -automatically connected at the master and slave drivers. The user may then push -modules onto either side of the stream pair. -.sp -.LP -The master and slave drivers pass all messages to their adjacent queues. Only -the \fBM_FLUSH\fR needs some processing. Because the read queue of one side is -connected to the write queue of the other, the \fBFLUSHR\fR flag is changed to -the \fBFLUSHW\fR flag and vice versa. When the master device is closed an -\fBM_HANGUP\fR message is sent to the slave device which will render the device -unusable. The process on the slave side gets the errno \fBEIO\fR when -attempting to write on that stream but it will be able to read any data -remaining on the stream head read queue. When all the data has been read, -\fBread()\fR returns 0 indicating that the stream can no longer be used. On the -last close of the slave device, a 0-length message is sent to the master -device. When the application on the master side issues a \fBread()\fR or -\fBgetmsg()\fR and 0 is returned, the user of the master device decides whether -to issue a \fBclose()\fR that dismantles the pseudo-terminal subsystem. If the -master device is not closed, the pseudo-tty subsystem will be available to -another user to open the slave device. -.sp -.LP -If \fBO_NONBLOCK\fR or \fBO_NDELAY\fR is set, read on the master side returns -\(mi1 with errno set to \fBEAGAIN\fR if no data is available, and write returns -\(mi1 with errno set to \fBEAGAIN\fR if there is internal flow control. -.SH IOCTLS -.sp -.LP -The master driver supports the \fBISPTM\fR and \fBUNLKPT\fR ioctls that are -used by the functions \fBgrantpt\fR(3C), \fBunlockpt\fR(3C) and -\fBptsname\fR(3C). The ioctl \fBISPTM\fR determines whether the file descriptor -is that of an open master device. On success, it returns the 0. The ioctl -\fBUNLKPT\fR unlocks the master and slave devices. It returns 0 on success. On -failure, the errno is set to \fBEINVAL\fR indicating that the master device is -not open. -.SH FILES -.sp -.ne 2 -.na -\fB\fB/dev/ptmx\fR\fR -.ad -.RS 14n -master clone device -.RE - -.sp -.ne 2 -.na -\fB\fB/dev/pts/M\fR\fR -.ad -.RS 14n -slave devices (M = 0 -> N-1) -.RE - -.SH SEE ALSO -.sp -.LP -\fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBunlockpt\fR(3C), \fBpckt\fR(7M), -\fBpts\fR(7D) -.sp -.LP -\fISTREAMS Programming Guide\fR +.\" Copyright 2022 Oxide Computer Company +.Dd February 5, 2022 +.Dt PTM 7D +.Os +.Sh NAME +.Nm ptm , +.Nm pts +.Nd STREAMS pseudo-terminal manager and subsidiary drivers +.Sh SYNOPSIS +.Pa /dev/ptmx +.Pp +.Pa /dev/pts/* +.Sh DESCRIPTION +The pseudo-terminal subsystem simulates a terminal connection, where the +manager side represents the terminal and the subsidiary represents the user +process's special device end point. +The manager device is set up as a cloned device where its major device number +is the major for the clone device and its minor device number is the major for +the +.Nm ptm +driver; see +.Dv CLONE_DEV +in +.Xr ddi_create_minor_node 9F . +.Pp +There are no nodes in the file system for manager devices. +The manager pseudo driver is opened using the +.Xr open 2 +system call with +.Pa /dev/ptmx +as the device parameter. +The clone open finds the next available minor device for the +.Nm ptm +major device. +.Pp +A manager device is only available if it and its corresponding subsidiary +device are not already open. +Only one open is allowed on a manager device. +Multiple opens are allowed on the subsidiary device. +.Pp +When the manager device is opened, the corresponding subsidiary device is +automatically locked out. +No user may open the subsidiary device until its permissions are adjusted and +the device is unlocked by calling the functions +.Xr grantpt 3C +and +.Xr unlockpt 3C . +The user can then invoke the +.Xr open 2 +system call with the device name returned by the +.Xr ptsname 3C +function. +.Pp +After both the manager and subsidiary have been opened, the user has two file +descriptors which are the end points of a full duplex connection composed of +two streams which are automatically connected at the manager and subsidiary +drivers. +The user may then push modules onto either side of the stream pair. +Unless compiled in XPG4v2 mode +.Po +see +.Sx "XPG4v2 MODE" +.Pc , +the consumer needs to push the +.Xr ptem 7M +and +.Xr ldterm 7M +modules onto the subsidiary device to get terminal semantics. +.Pp +The manager and subsidiary drivers pass all messages to their adjacent queues. +Only the +.Dv M_FLUSH +needs some processing. +Because the read queue of one side is connected to the write queue of the +other, the +.Dv FLUSHR +flag is changed to the +.Dv FLUSHW +flag and vice versa. +.Pp +When the manager device is closed, an +.Dv M_HANGUP +message is sent to the subsidiary device which will render the device unusable. +The process on the subsidiary side gets an +.Er EIO +error when attempting to write on that stream, but it will be able to read +any data remaining on the stream head read queue. +When all the data has been read, +.Xr read 2 +returns +.Sy 0 +indicating that the stream can no longer be used. +.Pp +On the last close of the subsidiary device, a 0-length message is sent to the +manager device. +When the application on the manager side issues a +.Xr read 2 +or +.Xr getmsg 2 +and +.Sy 0 +is returned, the user of the manager device decides whether to issue a +.Xr close 2 +that dismantles the entire pseudo-terminal. +If the manager device is not closed, the pseudo-terminal will be available to +another user to open the subsidiary device. +.Pp +Since 0-length messages are used to indicate that the process on the +subsidiary side has closed, and should be interpreted that way by the process +on the manager side, applications on the subsidiary side should not write +0-length messages. +Unless the application is compiled in XPG4v2 mode +.Po +see +.Sx "XPG4v2 MODE" +.Pc , +then any 0-length messages written to the subsidiary device will be discarded +by the +.Xr ptem 7M +module. +.Pp +If +.Dv O_NONBLOCK +or +.Dv O_NDELAY +is set on the manager side: +.Bl -bullet +.It +Read on the manager side returns +.Sy -1 +with +.Va errno +set to +.Er EAGAIN +if no data is available +.It +Write returns +.Sy -1 +with +.Va errno +set to +.Er EAGAIN +if there is internal flow control +.El +.Pp +Standard STREAMS system calls can access pseudo-terminal devices. +The subsidiary devices support the +.Dv O_NDELAY +and +.Dv O_NONBLOCK +flags. +.Sh XPG4v2 MODE +.Em XPG4v2 +requires that subsidiary pseudo-terminal devices provide the process with an +interface that is identical to the terminal interface, without needing to +explicitly push any modules to achieve this. +It also requires that 0-length messages written on the subsidiary device will +be propagated to the manager device. +.Pp +Experience has shown that most software does not expect subsidiary +pseudo-terminal devices to operate in this manner. +This XPG4v2-compliant behaviour is only enabled in XPG4v2/SUS +.Po +see +.Xr standards 5 +.Pc +mode. +.Sh IOCTLS +The manager driver provides several ioctls to support the +.Xr grantpt 3C , +.Xr unlockpt 3C , +and +.Xr ptsname 3C +functions: +.Bl -tag -width Ds +.It Dv ISPTM +Determines whether the file descriptor is that of an open manager device. +On success, it returns the value +.Sy 0 . +.It Dv UNLKPT +Unlocks the manager and subsidiary devices. +It returns +.Sy 0 +on success. +On failure, +.Vt errno +is set to +.Vt EINVAL +indicating that the manager device is not open. +.El +.Sh FILES +.Bl -tag -width Pa +.It Pa /dev/ptmx +Pseudo-terminal manager clone device. +.It Pa /dev/pts/N +Pseudo-terminal subsidiary devices, where +.Sy N +is a non-negative integer. +Located via calls to +.Xr ptsname 3C . +.El +.Sh EXAMPLES +.Sy Example 1 +Opening the manager and subsidiary device for a pseudo-terminal. +.Bd -literal -offset Ds +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stropts.h> +#include <fcntl.h> +#include <err.h> +\&... +int fdm, fds; +char *subsidiaryname; +\&... +/* + * NOTE: Portable applications should use posix_openpt(3C) here: + */ +if ((fdm = open("/dev/ptmx", O_RDWR | O_NOCTTY)) < 0) { + err(1, "open manager"); +} +if (grantpt(fdm) != 0 || unlockpt(fdm) != 0 || + (subsidiaryname = ptsname(fdm)) == NULL) { + close(fdm); + err(1, "locate subsidiary"); +} +if ((fds = open(subsidiaryname, O_RDWR | O_NOCTTY)) < 0) { + close(fdm); + err(1, "open subsidiary"); +} +if (ioctl(fds, I_PUSH, "ptem") != 0 || + ioctl(fds, I_PUSH, "ldterm") != 0) { + close(fds); + close(fdm); + err(1, "push modules"); +} +.Ed +.Sh SEE ALSO +.Xr close 2 , +.Xr getmsg 2 , +.Xr open 2 , +.Xr read 2 , +.Xr grantpt 3C , +.Xr posix_openpt 3C , +.Xr ptsname 3C , +.Xr unlockpt 3C , +.Xr standards 5 , +.Xr ldterm 7M , +.Xr pckt 7M , +.Xr ptem 7M , +.Xr ddi_create_minor_node 9F diff --git a/usr/src/man/man7d/pts.7d b/usr/src/man/man7d/pts.7d deleted file mode 100644 index 6ac5bbcbd1..0000000000 --- a/usr/src/man/man7d/pts.7d +++ /dev/null @@ -1,107 +0,0 @@ -'\" te -.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association. -.\" Copyright 1992 Sun Microsystems -.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. -.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. -.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH PTS 7D "Feb 29, 2020" -.SH NAME -pts \- STREAMS pseudo-tty slave driver -.SH DESCRIPTION -The pseudo-tty subsystem simulates a terminal connection, where the master side -represents the terminal and the slave represents the user process's special -device end point. In order to use the pseudo-tty subsystem, a node for the -master side driver \fB/dev/ptmx\fR and N nodes for the slave driver (N is -determined at installation time) must be installed. The names of the slave -devices are \fB/dev/pts/M\fR where \fBM\fR has the values 0 through N-1. When -the master device is opened, the corresponding slave device is automatically -locked out. No user may open that slave device until its permissions are -adjusted and the device unlocked by calling functions \fBgrantpt\fR(3C) and -\fBunlockpt\fR(3C). The user can then invoke the open system call with the name -that is returned by the \fBptsname\fR(3C) function. See the example below. -.sp -.LP -Only one open is allowed on a master device. Multiple opens are allowed on the -slave device. After both the master and slave have been opened, the user has -two file descriptors which are end points of a full duplex connection composed -of two streams automatically connected at the master and slave drivers. The -user may then push modules onto either side of the stream pair. Unless compiled -in XPG4v2 mode (see below), the consumer needs to push the \fBptem\fR(7M) and -\fBldterm\fR(7M) modules onto the slave side of the pseudo-terminal subsystem -to get terminal semantics. -.sp -.LP -The master and slave drivers pass all messages to their adjacent queues. Only -the \fBM_FLUSH\fR needs some processing. Because the read queue of one side is -connected to the write queue of the other, the \fBFLUSHR\fR flag is changed to -the \fBFLUSHW\fR flag and vice versa. When the master device is closed an -\fBM_HANGUP\fR message is sent to the slave device which will render the device -unusable. The process on the slave side gets the errno \fBEIO\fR when -attempting to write on that stream but it will be able to read any data -remaining on the stream head read queue. When all the data has been read, read -returns 0 indicating that the stream can no longer be used. On the last close -of the slave device, a 0-length message is sent to the master device. When the -application on the master side issues a \fBread()\fR or \fBgetmsg()\fR and 0 is -returned, the user of the master device decides whether to issue a -\fBclose()\fR that dismantles the pseudo-terminal subsystem. If the master -device is not closed, the pseudo-tty subsystem will be available to another -user to open the slave device. Since 0-length messages are used to indicate -that the process on the slave side has closed and should be interpreted that -way by the process on the master side, applications on the slave side should -not write 0-length messages. Unless the application is compiled in XPG4v2 mode -(see below) then any 0-length messages written on the slave side will be -discarded by the \fBptem\fR module. -.sp -.LP -The standard STREAMS system calls can access the pseudo-tty devices. The slave -devices support the \fBO_NDELAY\fR and \fBO_NONBLOCK\fR flags. -.SH XPG4v2 MODE -XPG4v2 requires that open of a slave pseudo terminal device provides the -process with an interface that is identical to the terminal interface (without -having to explicitly push any modules to achieve this). It also requires that -0-length messages written on the slave side will be propagated to the master. -.sp -Experience has shown, however, that most software does not expect slave pty -devices to operate in this manner and therefore this XPG4v2-compliant -behaviour is only enabled in XPG4v2/SUS (see \fBstandards\fR(5)) mode. -.SH EXAMPLES -.in +2 -.nf -int fdm fds; -char *slavename; -extern char *ptsname(); - -fdm = open("/dev/ptmx", O_RDWR); /* open master */ -grantpt(fdm); /* change permission of slave */ -unlockpt(fdm); /* unlock slave */ -slavename = ptsname(fdm); /* get name of slave */ -fds = open(slavename, O_RDWR); /* open slave */ -ioctl(fds, I_PUSH, "ptem"); /* push ptem */ -ioctl(fds, I_PUSH, "ldterm"); /* push ldterm*/ -.fi -.in -2 - -.SH FILES -.ne 2 -.na -\fB\fB/dev/ptmx\fR\fR -.ad -.RS 14n -master clone device -.RE - -.sp -.ne 2 -.na -\fB\fB/dev/pts/M\fR\fR -.ad -.RS 14n -slave devices (M = 0 -> N-1) -.RE - -.SH SEE ALSO -\fBgrantpt\fR(3C), \fBptsname\fR(3C), \fBunlockpt\fR(3C), \fBldterm\fR(7M), -\fBptm\fR(7D), \fBptem\fR(7M), \fBstandards\fR(5) -.sp -.LP -\fISTREAMS Programming Guide\fR diff --git a/usr/src/man/man7d/pty.7d b/usr/src/man/man7d/pty.7d index e2f85c3224..8e14dd3ea2 100644 --- a/usr/src/man/man7d/pty.7d +++ b/usr/src/man/man7d/pty.7d @@ -3,244 +3,263 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH PTY 7D "Aug 8, 1994" -.SH NAME -pty \- pseudo-terminal driver -.SH DESCRIPTION -.sp -.LP -The \fBpty\fR driver provides support for a pair of devices collectively known -as a \fIpseudo-terminal\fR. The two devices comprising a pseudo-terminal are -known as a \fIcontroller\fR and a \fIslave\fR. The slave device distinguishes -between the \fBB0\fR baud rate and other baud rates specified in the -\fBc_cflag\fR word of the \fBtermios\fR structure, and the \fBCLOCAL\fR flag in -that word. It does not support any of the other \fBtermio\fR(7I) device control -functions specified by flags in the \fBc_cflag\fR word of the \fBtermios\fR -structure and by the \fB\fR\fBIGNBRK\fR\fB, \fR \fB\fR\fBIGNPAR\fR\fB, \fR -\fB\fR\fBPARMRK\fR\fB, \fR or \fBINPCK\fR flags in the \fBc_iflag\fR word of -the \fBtermios\fR structure, as these functions apply only to asynchronous -serial ports. All other \fBtermio\fR(7I) functions must be performed by -\fBSTREAMS\fR modules pushed atop the driver; when a slave device is opened, -the \fBldterm\fR(7M) and \fBttcompat\fR(7M) \fBSTREAMS\fR modules are -automatically pushed on top of the stream, providing the standard -\fBtermio\fR(7I) interface. -.sp -.LP +.\" Copyright 2022 Oxide Computer Company +.Dd February 5, 2022 +.Dt PTY 7D +.Os +.Sh NAME +.Nm pty +.Nd legacy pseudo-terminal driver +.Sh SYNOPSIS +.Pa /dev/pty[p-r]* +.Pp +.Pa /dev/tty[p-r]* +.Sh DESCRIPTION +This driver provides support for legacy static pseudo-terminal devices. +Modern software does not use this driver, preferring instead the STREAMS-based +.Xr ptm 7D +and +.Xr pts 7D +pseudo-terminal drivers, consumed through the portable +.Xr posix_openpt 3C +interface. +.Pp +The +.Nm pty +driver provides support for a pair of devices collectively known +as a +.Em pseudo-terminal . +The two devices comprising a pseudo-terminal are known as a +.Em manager +and a +.Em subsidiary . +The subsidiary device distinguishes between the +.Dv B0 baud rate and other baud rates specified in +the +.Fa c_cflag +field of the +.Vt termios +structure, and the +.Dv CLOCAL +flag in that member. +It does not support any of the other +.Xr termio 7I +device control functions specified by flags in the +.Fa c_cflag +field of the +.Vt termios +structure and by the +.Dv IGNBRK , +.Dv IGNPAR , +.Dv PARMRK , +or +.Dv INPCK +flags in the +.Fa c_iflag +field of the +.Vt termios +structure, as these functions apply only to asynchronous serial ports. +All other +.Xr termio 7I +functions must be performed by STREAMS modules pushed atop the driver; when a +subsidiary device is opened, the +.Xr ldterm 7M +and +.Xr ttcompat 7M +STREAMS modules are automatically pushed on top of the stream, providing the +standard +.Xr termio 7I +interface. +.Pp Instead of having a hardware interface and associated hardware that supports the terminal functions, the functions are implemented by another process -manipulating the controller device of the pseudo-terminal. -.sp -.LP -The controller and the slave devices of the pseudo-terminal are tightly -connected. Any data written on the controller device is given to the slave -device as input, as though it had been received from a hardware interface. Any -data written on the slave terminal can be read from the controller device -(rather than being transmitted from a \fBUAR\fR). -.sp -.LP -By default, 48 pseudo-terminal pairs are configured as follows: -.sp -.in +2 -.nf -/dev/pty[p-r][0-9a-f] controller devices -/dev/tty[p-r][0-9a-f] slave devices -.fi -.in -2 - -.SH IOCTLS -.sp -.LP -The standard set of \fBtermio ioctl\fRs are supported by the slave device. -None of the bits in the \fBc_cflag\fR word have any effect on the -pseudo-terminal, except that if the baud rate is set to \fBB0\fR, it will -appear to the process on the controller device as if the last process on the -slave device had closed the line; thus, setting the baud rate to \fBB0\fR has -the effect of ``hanging up'' the pseudo-terminal, just as it has the effect of -``hanging up'' a real terminal. -.sp -.LP -There is no notion of ``parity'' on a pseudo-terminal, so none of the flags in -the \fBc_iflag\fR word that control the processing of parity errors have any -effect. Similarly, there is no notion of a ``break'', so none of the flags that -control the processing of breaks, and none of the \fBioctl\fRs that generate -breaks, have any effect. -.sp -.LP +manipulating the manager device of the pseudo-terminal. +.Pp +The manager and the subsidiary devices of the pseudo-terminal are tightly +connected. +Any data written on the manager device is given to the subsidiary device as +input, as though it had been received from a hardware interface. +Any data written on the subsidiary terminal can be read from the manager device +.Pq "rather than being transmitted from a UAR" . +.Pp +The driver is statically configured to provide 48 pseudo-terminal pairs. +Software that requires dynamic pseudo-terminal devices, or a greater number +of devices, must be converted to use +.Xr ptm 7D . +.Sh IOCTLS +The standard set of +.Xr termio 7I +ioctls are supported by the subsidiary device. +None of the bits in the +.Fa c_cflag +field have any effect on the pseudo-terminal, except that if the baud rate is +set to +.Dv B0 , +it will appear to the process on the manager device as if the last process on +the subsidiary device had closed the line; thus, setting the baud rate to +.Dv B0 +has the effect of +.Dq hanging up +the pseudo-terminal, just as it has the effect of +.Dq hanging up +a real terminal. +.Pp +There is no notion of +.Dq parity +on a pseudo-terminal, so none of the flags in the +.Fa c_iflag +field that control the processing of parity errors have any +effect. +Similarly, there is no notion of a +.Fa break , +so none of the flags that control the processing of breaks, and none of the +ioctls that generate breaks, have any effect. +.Pp Input flow control is automatically performed; a process that attempts to write -to the controller device will be blocked if too much unconsumed data is -buffered on the slave device. The input flow control provided by the -\fBIXOFF\fR flag in the \fBc_iflag\fR word is not supported. -.sp -.LP -The delays specified in the \fBc_oflag\fR word are not supported. -.sp -.LP -As there are no modems involved in a pseudo-terminal, the \fBioctl\fRs that -return or alter the state of modem control lines are silently ignored. -.sp -.LP -A few special \fBioctl\fRs are provided on the controller devices of -pseudo-terminals to provide the functionality needed by applications programs -to emulate real hardware interfaces: -.sp -.ne 2 -.na -\fB\fBTIOCSTOP\fR\fR -.ad -.RS 14n -The argument is ignored. Output to the pseudo-terminal is suspended, as if a -\fBSTOP\fR character had been typed. -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCSTART\fR\fR -.ad -.RS 14n -The argument is ignored. Output to the pseudo-terminal is restarted, as if a -\fBSTART\fR character had been typed. -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCPKT\fR\fR -.ad -.RS 14n -The argument is a pointer to an \fBint\fR. If the value of the \fBint\fR is -non-zero, \fIpacket\fR mode is enabled; if the value of the \fBint\fR is zero, -packet mode is disabled. When a pseudo-terminal is in packet mode, each -subsequent \fBread\fR(2) from the controller device will return data written on -the slave device preceded by a zero byte (symbolically defined as -\fB\fR\fBTIOCPKT_DATA\fR\fB), \fR or a single byte reflecting control status -information. In the latter case, the byte is an inclusive-or of zero or more -of the bits: -.sp -.ne 2 -.na -\fB\fBTIOCPKT_FLUSHREAD\fR\fR -.ad -.RS 22n -whenever the read queue for the terminal is flushed. -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCPKT_FLUSHWRITE\fR\fR -.ad -.RS 22n -whenever the write queue for the terminal is flushed. -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCPKT_STOP\fR\fR -.ad -.RS 22n -whenever output to the terminal is stopped using ^S. -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCPKT_START\fR\fR -.ad -.RS 22n -whenever output to the terminal is restarted. -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCPKT_DOSTOP\fR\fR -.ad -.RS 22n -whenever \fBXON/XOFF\fR flow control is enabled after being disabled; it is -considered ``enabled'' when the \fBIXON\fR flag in the \fBc_iflag\fR word is -set, the \fBVSTOP\fR member of the \fBc_cc\fR array is ^S and the \fBVSTART\fR -member of the \fBc_cc\fR array is ^Q. -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCPKT_NOSTOP\fR\fR -.ad -.RS 22n -whenever \fBXON/XOFF\fR flow control is disabled after being enabled. -.RE - -.RE - -.sp -.ne 2 -.na -\fB\fBTIOCREMOTE\fR\fR -.ad -.RS 14n -The argument is a pointer to an \fBint\fR. If the value of the \fBint\fR is -non-zero, \fIremote\fR mode is enabled; if the value of the \fBint\fR is zero, -remote mode is disabled. This mode can be enabled or disabled independently of -packet mode. When a pseudo-terminal is in remote mode, input to the slave -device of the pseudo-terminal is flow controlled and not input edited -(regardless of the mode the slave side of the pseudo-terminal). Each write to -the controller device produces a record boundary for the process reading the -slave device. In normal usage, a write of data is like the data typed as a -line on the terminal; a write of 0 bytes is like typing an \fBEOF\fR character. -Note: this means that a process writing to a pseudo-terminal controller in -\fIremote\fR mode must keep track of line boundaries, and write only one line -at a time to the controller. If, for example, it were to buffer up several -\fBNEWLINE\fR characters and write them to the controller with one -\fBwrite()\fR, it would appear to a process reading from the slave as if a -single line containing several \fBNEWLINE\fR characters had been typed (as if, -for example, a user had typed the \fBLNEXT\fR character before typing all but -the last of those \fBNEWLINE\fR characters). Remote mode can be used when doing -remote line editing in a window manager, or whenever flow controlled input is -required. -.RE - -.SH EXAMPLES -.sp -.in +2 -.nf -#include <fcntl.h> -#include <sys/termios.h> - -int fdm fds; -fdm = open("/dev/ptyp0, O_RDWR); /* open master */ -fds = open("/dev/ttyp0, O_RDWR); /* open slave */ -.fi -.in -2 - -.SH FILES -.sp -.ne 2 -.na -\fB\fB/dev/pty[p-z][0-9a-f]\fR\fR -.ad -.RS 25n -pseudo-terminal controller devices -.RE - -.sp -.ne 2 -.na -\fB\fB/dev/tty[p-z][0-9a-f]\fR\fR -.ad -.RS 25n -pseudo-terminal slave devices -.RE - -.SH SEE ALSO -.sp -.LP -\fBrlogin\fR(1), \fBrlogind\fR(1M), \fBldterm\fR(7M), \fBtermio\fR(7I), -\fBttcompat\fR(7M), -.SH NOTES -.sp -.LP -It is apparently not possible to send an \fBEOT\fR by writing zero bytes in -\fBTIOCREMOTE\fR mode. +to the manager device will be blocked if too much unconsumed data is buffered +on the subsidiary device. +The input flow control provided by the +.Dv IXOFF +flag in the +.Fa c_iflag +field is not supported. +.Pp +The delays specified in the +.Fa c_oflag +field are not supported. +.Pp +As there are no modems involved in a pseudo-terminal, the ioctls that return or +alter the state of modem control lines are silently ignored. +.Pp +A few special ioctls are provided on the manager devices of pseudo-terminals to +provide the functionality needed by applications programs to emulate real +hardware interfaces: +.Bl -tag -width Ds +.It Dv TIOCSTOP +The argument is ignored. +Output to the pseudo-terminal is suspended, as if a +.Sy STOP +character had been typed. +.It Dv TIOCSTART +The argument is ignored. +Output to the pseudo-terminal is restarted, as if a +.Sy START +character had been typed. +.It Dv TIOCPKT +The argument is a pointer to an +.Vt int . +If the value of the +.Vt int +is non-zero, +.Em packet +mode is enabled; if the value of the +.Vt int +is zero, packet mode is disabled. +When a pseudo-terminal is in packet mode, each subsequent +.Xr read 2 +from the manager device will return data written on the subsidiary device +preceded by a zero byte +.Po +symbolically defined as +.Dv TIOCPKT_DATA +.Pc , +or a single byte reflecting control status information. +In the latter case, the byte is an inclusive-or of zero or more of the bits: +.Bl -tag -width Ds +.It Dv TIOCPKT_FLUSHREAD +Whenever the read queue for the terminal is flushed. +.It Dv TIOCPKT_FLUSHWRITE +Whenever the write queue for the terminal is flushed. +.It Dv TIOCPKT_STOP +Whenever output to the terminal is stopped using +.Sy ^S . +.It Dv TIOCPKT_START +Whenever output to the terminal is restarted. +.It Dv TIOCPKT_DOSTOP +Whenever +.Em XON/XOFF +flow control is enabled after being disabled; it is +considered +.Dq enabled +when the +.Dv IXON +flag in the +.Fa c_iflag +field is set, the +.Dv VSTOP +member of the +.Fa c_cc +array is +.Sy ^S +and the +.Dv VSTART +member of the +.Fa c_cc +array is +.Sy ^Q. +.It Dv TIOCPKT_NOSTOP +Whenever +.Em XON/XOFF +flow control is disabled after being enabled. +.El +.It Dv TIOCREMOTE +The argument is a pointer to an +.Vt int . +If the value of the +.Vt int +is non-zero, +.Em remote +mode is enabled; if the value of the +.Vt int +is zero, remote mode is disabled. +This mode can be enabled or disabled independently of packet mode. +When a pseudo-terminal is in remote mode, input to the subsidiary device of the +pseudo-terminal is flow controlled and not input edited (regardless of the mode +the subsidiary side of the pseudo-terminal). +.Pp +Each write to the manager device produces a record boundary for the process +reading the subsidiary device. +In normal usage, a write of data is like the data typed as a line on the +terminal; a write of 0 bytes is like typing an +.Sy EOF +character. +Note: this means that a process writing to a pseudo-terminal manager in remote +mode must keep track of line boundaries, and write only one line at a time to +the manager. +.Pp +If, for example, it were to buffer up several newline characters and write them +to the manager with one +.Xr write 2 , +it would appear to a process reading from the subsidiary as if a single line +containing several newline characters had been typed +.Po +as if, for example, a user had typed the literal next +.Pq Sy LNEXT +character before typing all but the last of those newline characters +.Pc . +Remote mode can be used when doing remote line editing in a window manager, or +whenever flow controlled input is required. +.El +.Sh FILES +.Bl -tag -width Pa +.It Pa /dev/pty[p-r][0-9a-f] +Pseudo-terminal manager devices. +.It Pa /dev/tty[p-r][0-9a-f] +Pseudo-terminal subsidiary devices. +.El +.Sh SEE ALSO +.Xr rlogin 1 , +.Xr rlogind 1M , +.Xr posix_openpty 3C , +.Xr ptm 7D , +.Xr termio 7I , +.Xr ldterm 7M , +.Xr ttcompat 7M +.Sh NOTES +This is a legacy device and should not be used by new software. +.Pp +It is apparently not possible to send an +.Sy EOT +by writing zero bytes in +.Dv TIOCREMOTE +mode. diff --git a/usr/src/man/man7d/zcons.7d b/usr/src/man/man7d/zcons.7d index 433daddbcf..07df6b458e 100644 --- a/usr/src/man/man7d/zcons.7d +++ b/usr/src/man/man7d/zcons.7d @@ -3,73 +3,62 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH ZCONS 7D "Aug 24, 2003" -.SH NAME -zcons \- Zone console device driver -.SH DESCRIPTION -.sp -.LP -The \fBzcons\fR character driver exports the console for system zones. The -driver is comprised of two "sides:" a master side with which applications in -the global zone communicate, and a slave side, which receives I/O from the -master side. The slave side is available in the global zones. -.sp -.LP -Applications must not depend on the location of \fB/dev\fR or \fB/devices\fR -entries exported by \fBzcons\fR. Inside a zone, the \fBzcons\fR slave side is -fronted by \fB/dev/console\fR and other console-related symbolic links, which -are used by applications that expect to write to the system console. -.sp -.LP -The \fBzcons\fR driver is Sun Private, and may change in future releases. -.SH FILES -.sp -.ne 2 -.na -\fB\fB/dev/zcons/<\fIzonename\fR>/masterconsole\fR \fR -.ad -.sp .6 -.RS 4n -Global zone master side console for zone <\fIzonename\fR>. -.RE - -.sp -.ne 2 -.na -\fB\fB/dev/zcons/<\fIzonename\fR>/slaveconsole\fR \fR -.ad -.sp .6 -.RS 4n -Global zone slave side console for zone <\fIzonename\fR>. -.RE - -.sp -.ne 2 -.na -\fB\fB/dev/zconsole\fR \fR -.ad -.sp .6 -.RS 4n -Non-global zone console (slave side). -.RE - -.SH ATTRIBUTES -.sp -.LP -See \fBattributes\fR(5) for descriptions of the following attributes: -.sp - -.sp -.TS -box; -c | c -l | l . -ATTRIBUTE TYPE ATTRIBUTE VALUE -_ - Interface Stability Sun Private -.TE - -.SH SEE ALSO -.sp -.LP -\fBzoneadm\fR(1M), \fBzonecfg\fR(1M), \fBattributes\fR(5), \fBzones\fR(5) +.\" Copyright 2022 Oxide Computer Company +.Dd February 5, 2022 +.Dt ZCONS 7D +.Os +.Sh NAME +.Nm zcons +.Nd Zone console device driver +.Sh DESCRIPTION +The +.Nm zcons +character driver exports the console for system zones. +The driver is fundamentally similar to a pseudo-terminal device, and is thus +comprised of two sides: +.Bl -bullet +.It +a manager device, which applications in the global zone can open for +communication +.It +a subsidiary device, which processes in the non-global zone can write to, to +communicate with global zone management applications +.El +.Pp +Applications must not depend on the location of +.Pa /dev +or +.Pa /devices +entries exposed by +.Nm zcons +in the global zone. +Inside a non-global zone, the +.Nm zcons +subsidiary device is fronted by +.Pa /dev/console +and other console-related symbolic links, which are used by applications that +expect to write to the system console. +.Pp +The +.Nm +driver is not a +.Sy Committed +interface, and may change at any time. +.Sh FILES +.Bl -tag -width Pa +.It Pa /dev/zcons/ZONENAME/globalconsole +Global zone console manager device for zone +.Sy ZONENAME . +.It Pa /dev/zcons/ZONENAME/zoneconsole +Global zone console subsidiary device for zone +.Sy ZONENAME . +.It Pa /dev/zconsole +Non-global zone console (subsidiary device). +.El +.Sh INTERFACE STABILITY +.Sy Uncommitted +.Sh SEE ALSO +.Xr zoneadm 1M , +.Xr zonecfg 1M , +.Xr attributes 5 , +.Xr zones 5 diff --git a/usr/src/man/man7m/pckt.7m b/usr/src/man/man7m/pckt.7m index 9cb6149cd5..909e1e0367 100644 --- a/usr/src/man/man7m/pckt.7m +++ b/usr/src/man/man7m/pckt.7m @@ -3,21 +3,18 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH PCKT 7M "Jul 3, 1990" +.TH PCKT 7M "Feb 5, 2022" .SH NAME pckt \- STREAMS Packet Mode module .SH SYNOPSIS -.LP .nf int ioctl(\fI fd, \fRI_PUSH, "pckt"); .fi .SH DESCRIPTION -.sp -.LP \fBpckt\fR is a STREAMS module that may be used with a pseudo terminal to packetize certain messages. The \fBpckt\fR module should be pushed (see -\fBI_PUSH\fR on \fBstreamio\fR(7I)) onto the master side of a pseudo terminal. +\fBI_PUSH\fR on \fBstreamio\fR(7I)) onto the manager side of a pseudo terminal. .sp .LP Packetizing is performed by prefixing a message with an \fBM_PROTO\fR message. @@ -31,21 +28,19 @@ On the read-side, only the \fBM_PROTO\fR, \fBM_PCPROTO\fR, \fBM_STOP\fR, types are passed upstream unmodified. .sp .LP -Since all unread state information is held in the master's stream head read +Since all unread state information is held in the manager's stream head read queue, flushing of this queue is disabled. .sp .LP On the write-side, all messages are sent down unmodified. .sp .LP -With this module in place, all reads from the master side of the pseudo +With this module in place, all reads from the manager side of the pseudo terminal should be performed with the \fBgetmsg\fR(2) or \fBgetpmsg\fR() function. The control part of the message contains the message type. The data part contains the actual data associated with that message type. The onus is on the application to separate the data into its component parts. .SH SEE ALSO -.sp -.LP \fBgetmsg\fR(2), \fBioctl\fR(2), \fBldterm\fR(7M), \fBptem\fR(7M), \fBstreamio\fR(7I), \fBtermio\fR(7I) .sp diff --git a/usr/src/man/man7m/ptem.7m b/usr/src/man/man7m/ptem.7m index aefea791d6..0a5354b222 100644 --- a/usr/src/man/man7m/ptem.7m +++ b/usr/src/man/man7m/ptem.7m @@ -4,65 +4,127 @@ .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH PTEM 7M "Jul 3, 1990" -.SH NAME -ptem \- STREAMS Pseudo Terminal Emulation module -.SH SYNOPSIS -.LP -.nf -\fBint ioctl(\fR\fIfd\fR, \fBI_PUSH\fR,\fB "ptem");\fR -.fi - -.SH DESCRIPTION -.sp -.LP -\fBptem\fR is a STREAMS module that, when used in conjunction with a line -discipline and pseudo terminal driver, emulates a terminal. -.sp -.LP -The \fBptem\fR module must be pushed (see \fBI_PUSH\fR, \fBstreamio\fR(7I)) -onto the slave side of a pseudo terminal STREAM, before the \fBldterm\fR(7M) +.\" Copyright 2022 Oxide Computer Company +.Dd February 5, 2022 +.Dt PTEM 7M +.Os +.Sh NAME +.Nm ptem +.Nd STREAMS Pseudo-Terminal Emulation module +.Sh SYNOPSIS +.In unistd.h +.In stropts.h +.Ft int +.Fo ioctl +.Fa "int fildes" , +.Dv I_PUSH , +.Qq ptem +.Fc +.Sh DESCRIPTION +.Nm ptem +is a STREAMS module that emulates a terminal device when used in conjunction +with the line discipline, +.Xr ldterm 7M , +and the pseudo terminal driver, +.Xr ptm 7D . +.Pp +The +.Nm ptem +module must be pushed +.Po +see +.Dv I_PUSH +in +.Xr streamio 7I +.Pc +onto the subsidiary device of a pseudo-terminal STREAM, before the +.Xr ldterm 7M module is pushed. -.sp -.LP -On the write-side, the \fBTCSETA\fR, \fBTCSETAF\fR, \fBTCSETAW\fR, -\fBTCGETA\fR, \fBTCSETS\fR, \fBTCSETSW\fR, \fBTCSETSF\fR, \fBTCGETS\fR, -\fBTCSBRK\fR, \fBJWINSIZE\fR, \fBTIOCGWINSZ\fR, and \fBTIOCSWINSZ\fR -\fBtermio\fR \fBioctl\fR(2) messages are processed and acknowledged. If remote -mode is not in effect, \fBptem\fR handles the \fBTIOCSTI\fR ioctl by copying -the argument bytes into an \fBM_DATA\fR message and passing it back up the -read side. Regardless of the remote mode setting, \fBptem\fR acknowledges the -ioctl and passes a copy of it downstream for possible further processing. A -hang up (that is, \fBstty 0\fR) is converted to a zero length \fBM_DATA\fR -message and passed downstream. Termio \fBcflags\fR and window row and column -information are stored locally one per stream. \fBM_DELAY\fR messages are -discarded. All other messages are passed downstream unmodified. -.sp -.LP -On the read-side all messages are passed upstream unmodified with the following -exceptions. All \fBM_READ\fR and \fBM_DELAY\fR messages are freed in both -directions. A \fBTCSBRK\fR ioctl is converted to an \fBM_BREAK\fR message and -passed upstream and an acknowledgement is returned downstream. A -\fBTIOCSIGNAL\fR ioctl is converted into an \fBM_PCSIG\fR message, and passed -upstream and an acknowledgement is returned downstream. Finally a -\fBTIOCREMOTE\fR ioctl is converted into an \fBM_CTL\fR message, acknowledged, -and passed upstream; the resulting mode is retained for use in subsequent -\fBTIOCSTI\fR parsing. -.SH FILES -.sp -.ne 2 -.na -\fB<\fBsys/ptem.h\fR> \fR -.ad -.RS 17n - -.RE - -.SH SEE ALSO -.sp -.LP -\fBstty\fR(1), \fBioctl\fR(2), \fBldterm\fR(7M), \fBpckt\fR(7M), -\fBstreamio\fR(7I), \fBtermio\fR(7I) -.sp -.LP -\fISTREAMS Programming Guide\fR +.Ss Write-side Behaviour +The +.Dv TCSETA , +.Dv TCSETAF , +.Dv TCSETAW , +.Dv TCGETA , +.Dv TCSETS , +.Dv TCSETSW , +.Dv TCSETSF , +.Dv TCGETS , +.Dv TCSBRK , +.Dv JWINSIZE , +.Dv TIOCGWINSZ , +and +.Dv TIOCSWINSZ +.Xr termio 7I +.Xr ioctl 2 +messages are processed and acknowledged. +.Pp +If +.Em remote mode +is not in effect, +.Nm ptem +handles the +.Dv TIOCSTI +ioctl by copying the argument bytes into an +.Dv M_DATA +message and passing it back up the read side. +Regardless of the +.Em remote mode +setting, +.Nm ptem +acknowledges the ioctl and passes a copy of it downstream for possible further +processing. +.Pp +A hang up +.Po +e.g., +.Ic stty 0 +.Pc +is converted to a zero length +.Dv M_DATA +message and passed downstream. +.Xr termio 7I +.Sy cflags +and window row and column information are stored locally, one per stream. +.Dv M_DELAY +messages are discarded. +.Pp +All other messages are passed downstream unmodified. +.Ss Read-side Behaviour +All messages are passed upstream unmodified with the following exceptions: +.Bl -bullet +.It +All +.Dv M_READ +and +.Dv M_DELAY +messages are freed in both directions. +.It +A +.Dv TCSBRK +ioctl is converted to an +.Dv M_BREAK +message and passed upstream and an acknowledgement is returned downstream. +.It +A +.Dv TIOCSIGNAL +ioctl is converted into an +.Dv M_PCSIG +message, passed upstream, and an acknowledgement is returned downstream. +.It +A +.Dv TIOCREMOTE +ioctl is converted into an +.Dv M_CTL +message, acknowledged, and passed upstream; the resulting mode is retained for +use in subsequent +.Dv TIOCSTI +parsing. +.El +.Sh SEE ALSO +.Xr stty 1 , +.Xr ioctl 2 , +.Xr streamio 7I , +.Xr termio 7I , +.Xr ldterm 7M , +.Xr pckt 7M |
