The enclosed patch makes clone try to acquire a controlling tty. This makes clone more useful because it enables job control in cloned sessions. The patch applies on current cvs head. Notes about the patch: - We don't call TIOCNOTTY if HAVE_SETSID: setsid() automatically detaches from the current controlling tty. - The logic for dup'ing the newly opened tty is changed for a better one. - Once the dup'ing of the newly opened tty is done, we try to acquire the newly opened tty as a controlling tty. We print a message if this fails. - We have to reset mypgrp to zero so that init_io() can get its job done correctly. Notes about controlling ttys: - Due to the way job control works, it is impossible for a process to acquire a controlling tty if another process already acquired it since: * POSIX mandates that if a session leader dies, all the processes in the session loose their controlling tty. * Most terminal emulator programs (including screen, but see note about screen) acquire a controlling tty before exec'ing their target process. - This means that the following won't work (the cloned zsh will run, but will not have a controlling tty (-> no job control)): * Open a new xterm. * Run tty in xterm. * Run in the xterm: exec zsh -c 'trap "" INT QUIT TSTP; while :; do sleep 100000; done' * Do a clone in the xterm's tty. - However this will work (the cloned zsh will have a controlling tty and job control will work): * clone /dev/tty or clone /dev/vc/ on linux * zsh will be able to open cloned shells with job control in a screen session as long as the screen "setsid off" command is in effect in the screen: + Run screen. You're now in screen #0. + Enter "setsid off": this is done by typing in: ^A : setsid off + Create a new screen. You're now in screen #1. + The shell in screen 1 has job control disabled (it has no controlling tty). + In screen #1, run: tty && exec sleep 1000000 + Switch back to screen #0: ^A 0 + Run clone on the tty that was printed in screen #1. + Switch back to screen #1: ^A 1 + You now have a cloned zsh with job control active. Tested to work OK on Linux (with TIOCNOTTY/TIOCSCTTY controlling tty acquiring method) and Solaris (with SvR4's O_NOCTTY controlling tty acquiring method). Phil. Changelog entry: 2003-07-22 Philippe Troin * Src/Modules/clone.c (bin_clone): Try to acquire a controlling tty when possible. Report failures. Cleanup.