home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / pty4 / part06 / CALLS next >
Encoding:
Text File  |  1992-02-18  |  9.3 KB  |  171 lines

  1. pty uses a bunch of syscalls (42 at last count) and library routines.
  2. Calls marked with * are BSD-only or otherwise not available on all UNIX
  3. systems. Calls marked with + are widely available but have different
  4. behavior on different systems---behavior different enough that pty might
  5. not work.
  6.  
  7. _exit: used in ptyerr.c for almost all exits. Note that pty does not use
  8.     stdio in any way.
  9. *accept: used in ptycomm.c`comm_accept, to accept a connection for the
  10.     master on a descriptor created by comm_read
  11. access: used with F_OK in ptyget.c to check if a pty bank (e.g., ttyq*)
  12.     exists
  13. *bind: used in ptycomm.c`comm_read to create the master's comm socket
  14. *bzero: used inside the system's FD_ZERO macro before select
  15. chdir: used once in the master and once in the sigler, both times in
  16.     ptymain.c, to switch permanently to PTYDIR.
  17. close: used throughout the program to get rid of a file descriptor.
  18.     Note that the return value from close is not checked---there's
  19.     absolutely no way pty could do anything about the descriptor in
  20.     case of an error, and it's far more important that the
  21.     descriptor be freed up than that NFS's perverted idea of UNIX
  22.     I/O be dealt with.
  23. *connect: used in ptycomm.c`comm_write to connect to a running master
  24. dup: used (1) in ptytty.c to try to find the controlling tty descriptor;
  25.     (2) in ptyslave.c to move the /dev/ttyxx descriptor to 0/1/2;
  26.     (3) in ptysecure.c to set up descriptors for /bin/ps
  27. *dup2: used in ptymisc.c to move a /dev/null descriptor around
  28. execve: used in ptysecure.c to invoke /bin/ps
  29. execvp: used in ptyslave.c to invoke the user's program, after setreuid
  30. *fchmod: used in ptysecure.c upon a slave tty descriptor
  31. +fcntl: used with F_GETFL in ptymisc.c (and sigsched.c) to see if a
  32.     descriptor is open
  33. flock: used in ptymisc.c for generic locking routine (used on log files)
  34. fork: used in ptymain.c (twice) to create master and slave processes;
  35.     used in ptysecure.c to invoke /bin/ps for security check
  36. free: used in ralloc.c`rfree
  37. *fstat: used in ptysecure.c upon a slave tty descriptor
  38. *getdtablesize: used in slave under -E to close all open descriptors;
  39.     used in ptymaster.c`closeallbut (which is a royal kludge)
  40. *getpgrp: used in ptytty.c`force_fg to plug into TIOCSPGRP; used in
  41.     ptymaster.c`contchild in preparation for killpg
  42. getpid: used (1) in the master to fill in a sesslog structure; (2) in
  43.     ptytty.c`force_fg to plug into getpgrp; (3) in the signaller to
  44.     send a WINCH to itself after reconnect; (4) in the slave to set
  45.     its pgrp before exec; (5) in the slave to pass to tctpgrp; (6)
  46.     to set up numbers for random tty searching; (7) in the master,
  47.     when fdctrlr asks for its pid; (8) in sigdfl.c to send a signal
  48.     to itself; (9) in ptysecure.c for various purposes.
  49. *getpwnam: used only in username.c
  50. *getpwuid: used only in username.c
  51. *geteuid: used in ptysecure.c as a secure pseudo-tty owner
  52. getuid: used once in ptytty.c to initialize a uid variable
  53. +ioctl: used in ptytty.c`ioc to control a tty descriptor; about two
  54.     dozen BSD-specific ioctls are used in ptytty.c
  55. +kill: used (1) in the master to tell the child to continue after the
  56.     sigler says so; (2) in the sigler to tell itself to WINCH after
  57.     a reconnect; (3) in sigdfl.c to send a signal to itself.
  58. *killpg: used in ptymaster.c`contchild to continue the child's process
  59.     group if a straight kill() failed
  60. *listen: used in ptycomm.c to prepare the master's comm socket for
  61.     connections
  62. lseek: used in ptylogs.c, sessconnlog.c, and sesslog.c to place a record
  63.     at a particular spot in a log file
  64. malloc: used in ralloc.c`ralloc
  65. +open: used (1) in ptyget.c with O_RDWR to open the master and slave
  66.     sides of a tty; (2) in ptylogs.c with O_RDWR, O_RDWR | O_APPEND,
  67.     and O_WRONLY | O_APPEND to open UTMP_FILE and WTMP_FILE; (3) in
  68.     ptymisc.c`forceopen upon /dev/null and /, to attempt to make
  69.     sure a descriptor is in use; (4) in ptyslave.c (twice) to open
  70.     /dev/tty with O_RDWR; (5) in ptytty.c`tty_getctrl to open
  71.     /dev/tty; (6) in sessconnlog.c and sesslog.c, with O_WRONLY |
  72.     O_CREAT and O_WRONLY | O_APPEND | O_CREAT (both mode 0644), to
  73.     open the sessnow, sesslog, scnow, and sclog system files for
  74.     update; (7) in ptysecure.c for various purposes.
  75. pipe: used (1) in ptymain.c to create pipes from the master to the
  76.     sigler and slave, so that there's no race between the master
  77.     setting up files and the sigler and slave starting; (2) in
  78.     ptysigler.c to create the master->sigler and sigler->master
  79.     pipes just before reconnect; (3) in ptysecure.c to create an
  80.     output pipe for /bin/ps.
  81. read
  82. *recvmsg: used in ptycomm.c to receive a descriptor from a UNIX-domain
  83.     socket. Note that recvmsg() is buggy in most BSD variants.
  84. *select: used (1) in ptymisc.c to pause briefly; (2) in sigsched.c to
  85.     check for usable descriptors.
  86. *sendmsg: used in ptycomm.c to send a descriptor down a UNIX-domain
  87.     socket. Note that sendmsg() is buggy in some BSD variants.
  88. *setpgrp: used in ptyslave.c to set up pgrp of slave
  89. *setreuid: used in ptyslave.c to make sure that slave runs as real uid;
  90.     used in ptysecure.c to make sure that /bin/ps runs as real uid;
  91.     used in ptymain.c to make sure that master is safe from user
  92. *sigblock: used in sigdfl.c and sigsched.c for various purposes
  93. +signal: used in various spots to set handlers to SIG_{IGN,DFL}
  94. *sigsetmask: used in sigdfl.c and sigsched.c for various purposes
  95. *sigvec: used in sigdfl.c and sigsched.c to install signal handlers
  96. *socket: used in ptycomm.c`comm_{read,write} to set up comm socket
  97. strcpy: used in env.c for various purposes
  98. strlen: used throughout the code for various purposes
  99. strncmp: used in env.c and ptylogs.c
  100. strncpy: used in ptylogs.c, sessconnlog.c, sesslog.c
  101. time: used in ptymisc.c`now
  102. unlink: used only in ptycomm.c, upon a restricted pathname, to remove
  103.     an obsolete communications socket.
  104. *wait3: used in both master and sigler to wait for children (in the
  105.     latter case, simply to get rid of zombies), with NOHANG and
  106.     UNTRACED.
  107. write
  108.  
  109. Note that pty also depends on environ and errno.
  110.  
  111. The BSD-specific calls can be divided into several groups:
  112.  
  113. A (pty allocation). Lots of vendors have added pseudo-ttys. In the BSD
  114. world, everyone simply copied what Berkeley did. Unfortunately, System V
  115. is graced with at least nine pseudo-tty allocation mechanisms; there are
  116. probably many more which I haven't seen. ptyget.c and ptysecure.c have
  117. to be completely rewritten for each new allocation design. On the other
  118. hand, there must be code which uses the ptys on that system, so this is
  119. certainly a doable job.
  120.  
  121. B (select). select (and the associated FD_ZERO [using bzero], FD_ISSET,
  122. and FD_SET macros) is the foundation of the sigsched library, which
  123. literally runs everything. select also uses the largest part of pty's
  124. run time. It would be incredibly difficult to simulate select() with a
  125. less powerful mechanism, such as poll(). I would have to be exceedingly
  126. bored before attempting to port pty to a system without select().
  127.  
  128. C (communication, including fd passing). accept, bind, connect, listen,
  129. recvmsg, sendmsg, and socket are isolated inside ptycomm.c. You can rip
  130. out the entire ptycomm.c mechanism and replace it with anything which
  131. (1) allows client-server connections with some security; (2) lets
  132. read(), write(), and select() work; (3) provides file descriptor
  133. passing; (4) allows a two-way connection on a single descriptor. Most
  134. streams facilities can handle (3). Note that if the file descriptor
  135. passing mechanism isn't as buggy as BSD's, you can get rid of
  136. ptymisc.c`gaargh.
  137.  
  138. D (job control). getpgrp(), setpgrp(), the TIOCSPGRP and TIOCGPGRP
  139. ioctls, various signals, kill(,SIGCONT), killpg, and wait3 are all part
  140. of the BSD job control system. pty puts quite a bit of effort into
  141. handling job control, but not nearly as much as the previous version. I
  142. really can't guess what will go wrong if you simply rip out all the job
  143. control code and replace wait3() with an appropriate wait().
  144.  
  145. E (tty handling). SIGWINCH and some two dozen tty ioctls all depend on
  146. the BSD tty system. SIGWINCH is easy to take care of---it's already
  147. #ifdef'ed for TTY_WINDOWS. (pty works under BSD 4.2, which doesn't have
  148. SIGWINCH.) The other tty ioctls are isolated inside ptytty.c, which I
  149. will probably rewrite for POSIX if and when somebody asks me to.
  150. January 1992 update: Okay, I've now implemented TTY_TERMIO. POSIX, for
  151. some absolutely idiotic reason, doesn't stick to the traditional header
  152. files, but TTY_TERMIO should be good enough for systems with System V
  153. tty handling.
  154.  
  155. F (signal management). sigblock, sigsetmask, sigvec, and good old signal
  156. are all used throughout the pty code. POSIX can handle all of them, and
  157. I will do this port soon. System V cannot---it's very important that pty
  158. have reliable signal handling.
  159.  
  160. G (easy stuff). dup2, fcntl(,F_GETFL,0), getdtablesize, getpwnam,
  161. getpwuid, fchmod, fstat, and setreuid are all reasonably easy to handle.
  162. dup2() can be written in terms of F_DUPFD for System V; in fact, pty
  163. only uses it in a situation where it should be a no-op! (See
  164. ptymisc`forceopen and the calls to forceopen in ptymain.c.) F_GETFL is,
  165. I believe, available on all modern UNIX-like systems. getdtablesize can
  166. be replaced by NOFILE. setreuid(uid,uid) is essentially equivalent to
  167. setuid(uid). getpwnam() and getpwuid() appear on most systems, and when
  168. they don't appear, they're easy enough to write (just scan /etc/passwd).
  169. fchmod and fstat can be replaced by chmod and stat---they're only used
  170. in situations where the pathname is known (viz., a slave tty).
  171.