Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
5.4 KiB

28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
28 years ago
  1. .\" $OpenBSD: openpty.3,v 1.19 2017/04/20 19:30:42 jmc Exp $
  2. .\" Copyright (c) 1995
  3. .\" The Regents of the University of California. All rights reserved.
  4. .\"
  5. .\" This code is derived from software developed by the Computer Systems
  6. .\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
  7. .\" BG 91-66 and contributed to Berkeley.
  8. .\"
  9. .\" Redistribution and use in source and binary forms, with or without
  10. .\" modification, are permitted provided that the following conditions
  11. .\" are met:
  12. .\" 1. Redistributions of source code must retain the above copyright
  13. .\" notice, this list of conditions and the following disclaimer.
  14. .\" 2. Redistributions in binary form must reproduce the above copyright
  15. .\" notice, this list of conditions and the following disclaimer in the
  16. .\" documentation and/or other materials provided with the distribution.
  17. .\" 3. Neither the name of the University nor the names of its contributors
  18. .\" may be used to endorse or promote products derived from this software
  19. .\" without specific prior written permission.
  20. .\"
  21. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. .\" SUCH DAMAGE.
  32. .\"
  33. .Dd $Mdocdate: April 20 2017 $
  34. .Dt OPENPTY 3
  35. .Os
  36. .Sh NAME
  37. .Nm getptmfd ,
  38. .Nm openpty ,
  39. .Nm fdopenpty ,
  40. .Nm login_tty ,
  41. .Nm forkpty ,
  42. .Nm fdforkpty
  43. .Nd tty utility functions
  44. .Sh SYNOPSIS
  45. .In termios.h
  46. .In util.h
  47. .Ft int
  48. .Fn getptmfd "void"
  49. .Ft int
  50. .Fn openpty "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp"
  51. .Ft int
  52. .Fn fdopenpty "int ptmfd" "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp"
  53. .Ft int
  54. .Fn login_tty "int fd"
  55. .Ft pid_t
  56. .Fn forkpty "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp"
  57. .Ft pid_t
  58. .Fn fdforkpty "int ptmfd" "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp"
  59. .Sh DESCRIPTION
  60. The
  61. .Fn openpty ,
  62. .Fn login_tty ,
  63. and
  64. .Fn forkpty
  65. functions perform manipulations on ttys and pseudo-ttys.
  66. .Pp
  67. The
  68. .Fn openpty
  69. function finds an available pseudo-tty and returns file descriptors
  70. for the master and slave in
  71. .Fa amaster
  72. and
  73. .Fa aslave .
  74. If
  75. .Fa name
  76. is non-null, the filename of the slave is returned in
  77. .Fa name
  78. (a string of at least 16 characters).
  79. If
  80. .Fa termp
  81. is non-null, the terminal parameters of the slave will be set to the
  82. values in
  83. .Fa termp .
  84. If
  85. .Fa winp
  86. is non-null, the window size of the slave will be set to the values in
  87. .Fa winp .
  88. .Pp
  89. The
  90. .Fn openpty
  91. function allocates the pseudo-tty through the
  92. .Pa /dev/ptm
  93. device (see
  94. .Xr pty 4
  95. for details) which means that its ownership is changed to the UID of
  96. the caller, permissions are set to correct values, and all earlier
  97. uses of that device are revoked (see
  98. .Xr revoke 2
  99. for details).
  100. .Pp
  101. The
  102. .Fn fdopenpty
  103. and
  104. .Fn fdforkpty
  105. functions work like
  106. .Fn openpty
  107. and
  108. .Fn forkpty
  109. but expect a
  110. .Pa /dev/ptm
  111. file descriptor
  112. .Fa ptmfd
  113. obtained from the
  114. .Fn getptmfd
  115. function.
  116. .Pp
  117. The
  118. .Fn login_tty
  119. function prepares for a login on the tty
  120. .Fa fd
  121. (which may be a real tty device, or the slave of a pseudo-tty as
  122. returned by
  123. .Fn openpty )
  124. by creating a new session, making
  125. .Fa fd
  126. the controlling terminal for the current process, setting
  127. .Fa fd
  128. to be the standard input, output, and error streams of the current
  129. process, and closing
  130. .Fa fd .
  131. .Pp
  132. The
  133. .Fn forkpty
  134. function combines
  135. .Fn openpty ,
  136. .Fn fork ,
  137. and
  138. .Fn login_tty
  139. to create a new process operating in a pseudo-tty.
  140. The file
  141. descriptor of the master side of the pseudo-tty is returned in
  142. .Fa amaster ,
  143. and the filename of the slave in
  144. .Fa name
  145. if it is non-null.
  146. The
  147. .Fa termp
  148. and
  149. .Fa winp
  150. parameters, if non-null, will determine the terminal attributes and
  151. window size of the slave side of the pseudo-tty.
  152. .Sh RETURN VALUES
  153. If a call to
  154. .Fn openpty ,
  155. .Fn login_tty ,
  156. or
  157. .Fn forkpty
  158. is not successful, \-1 is returned and
  159. .Va errno
  160. is set to indicate the error.
  161. Otherwise,
  162. .Fn openpty ,
  163. .Fn login_tty ,
  164. and the child process of
  165. .Fn forkpty
  166. return 0, and the parent process of
  167. .Fn forkpty
  168. returns the process ID of the child process.
  169. .Sh FILES
  170. .Bl -tag -width /dev/tty[p-zP-T][0-9a-zA-Z]x -compact
  171. .It Pa /dev/pty[p-zP-T][0-9a-zA-Z]
  172. master pseudo terminals
  173. .It Pa /dev/tty[p-zP-T][0-9a-zA-Z]
  174. slave pseudo terminals
  175. .It Pa /dev/ptm
  176. pseudo terminal management device
  177. .El
  178. .Sh ERRORS
  179. .Fn getptmfd
  180. may fail and set
  181. .Va errno
  182. for any of the errors specified for the routine
  183. .Xr open 2 .
  184. .Pp
  185. .Fn openpty
  186. and
  187. .Fn fdopenpty
  188. will fail if:
  189. .Bl -tag -width Er
  190. .It Bq Er ENOENT
  191. There are no available ttys.
  192. .El
  193. .Pp
  194. .Fn fdopenpty
  195. and
  196. .Fn fdforkpty
  197. will fail if
  198. .Fn getptmfd
  199. fails.
  200. .Fn forkpty
  201. and
  202. .Fn fdforkpty
  203. will fail if either
  204. .Fn openpty
  205. or
  206. .Fn fork
  207. fails.
  208. .Pp
  209. .Fn login_tty
  210. will fail if
  211. .Fn ioctl
  212. fails to set
  213. .Fa fd
  214. to the controlling terminal of the current process.
  215. .Sh SEE ALSO
  216. .Xr fork 2 ,
  217. .Xr revoke 2 ,
  218. .Xr pty 4