Team BBL
Previous Page Next Page

Chapter 19

19.1

Both servers, telnetd and rlogind, run with superuser privileges, so their calls to chown and chmod succeed.

19.3

Execute pty -n stty -a to prevent the slave's termios structure and winsize structure from being initialized.

19.5

Unfortunately, the F_SETFL command of fcntl doesn't allow the readwrite status to be changed.

19.6

There are three process groups: (1) the login shell, (2) the pty parent and child, and (3) the cat process. The first two process groups constitute a session with the login shell as the session leader. The second session contains only the cat process. The first process group (the login shell) is a background process group, and the other two are foreground process groups.

19.7

First, cat terminates when it receives the end of file from its line discipline. This causes the PTY slave to terminate, which causes the PTY master to terminate. This in turn generates an end of file for the pty parent that's reading from the PTY master. The parent sends SIGTERM to the child, so the child terminates next. (The child doesn't catch this signal.) Finally, the parent calls exit(0) at the end of the main function.

The relevant output from the program shown in Figure 8.29 is

     cat             e =      270, chars =         274, stat =      0:
     pty             e =      262, chars =          40, stat =     15: F     X
     pty             e =      288, chars =         188, stat =      0:

19.8

This can be done with the shell's echo command and the date(1) command, all in a subshell:

   #!/bin/sh
   ( echo "Script started on " 'date';
     pty "${SHELL:-/bin/sh}";
     echo "Script done on " 'date' ) | tee typescript

19.9

The line discipline above the PTY slave has echo enabled, so whatever pty reads on its standard input and writes to the PTY master gets echoed by default. This echoing is done by the line discipline module above the slave even though the program (ttyname) never reads the data.

    Team BBL
    Previous Page Next Page