More signal-handling cleanup for ls.c. Do not allow signals to
commitadc30a8396b2b6cf1452ad1f0baa4b5bb9f93d33
authorJim Meyering <jim@meyering.net>
Sat, 24 Apr 2004 08:03:15 +0000 (24 08:03 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 24 Apr 2004 08:03:15 +0000 (24 08:03 +0000)
treea4c8310c20cf83d85c1509dfa52de3203c2ec136
parent8d90a312900c762f0c72d5baf17c0cb35c5626ca
More signal-handling cleanup for ls.c.  Do not allow signals to
happen between arbitrary output bytes, as the
restore-default-color sequence can bollix up multibyte chars or
color-change sequences in the ordinary output.  Instead, process
signals only between printing a file name and changing the color
back to non_filename_text color.  That way, if the signal handler
changes the color (to the default), 'ls' will change it back when
'ls' continues (after being suspended).

Also, do not bother with signal-handling unless stdout is a
controlling terminal; this lets stdio buffer better when "ls
--color" is piped or sent to a file.

(sigprocmask, sigset_t) [!defined SA_NOCLDSTOP]: New macros.
Do not include "full-write.h"; no longer needed.
(tcgetpgrp) [! HAVE_TCGETPGRP]: New macro.
(put_indicator_direct): Remove.  All callers changed to use
put_indicator.
(caught_signals, interrupt_signal, stop_signal_count): New vars.
(restore_default_color): Don't bother checking for put_indicator
failure.
(sighandler): Don't handle SIGTSTP; that's another handler now.
Simply set interrupt_signal to the signal, then exit.
(stophandler, process_signals): New functions.
(main): Don't output any color changes until _after_ the signal
handlers are set up.  This fixes a race condition where 'ls'
could be interrupted while initializing colors, and leaving the
terminal in an undesirable state.
Don't mess with signal-handling if standard output is not a
controlling terminal.
When exiting, restore the default color, then restore the
default signal handling, then act on any signals that weren't
acted on yet.
Do not print //DIRED// etc. in colors; this avoids the need
to catch signals when printing them.
(print_name_with_quoting): Process signals just before switching
color back to non_filename_text.
src/ls.c