Tidy up comments.

This commit is contained in:
Andrew Wood
2026-04-17 23:27:30 +01:00
parent 1b5a936ebf
commit 73d1237f1b
+59 -57
View File
@@ -26,14 +26,14 @@ void pv_crs_needreinit(pvcursorstate_t);
/* /*
* Ensure that terminal attribute TOSTOP is set. If we have to set it, * Check whether the terminal attribute TOSTOP is set. If it is not, set
* record that fact by setting "clear_tty_tostop_on_exit" to 1, so that in * it, and record that fact by setting "clear_tty_tostop_on_exit" to true,
* pv_sig_fini() we can turn it back off again. * so that pv_sig_fini() knows to clear it again.
* *
* In "-c" mode with IPC, then if we have to set TOSTOP, we also tell the * In "-c" mode with IPC, that flag is propagated to other PV instances via
* other PV instances about it via the shared "tty_tostop_added" flag, so * the shared "tty_tostop_added" flag, so those instances can set their own
* those instances can set their own on-exit flag, meaning that if any of * on-exit flag, meaning that if any of the PV instances set it, the last
* the PV instances set it, the last one to exit will clear it. * one to exit will clear it.
*/ */
static void pv_sig_ensure_tty_tostop() static void pv_sig_ensure_tty_tostop()
{ {
@@ -79,15 +79,15 @@ static void pv_sig_ensure_tty_tostop()
/* /*
* Handle SIGTTOU (tty output for background process) by setting the flag to * Handle SIGTTOU (tty output for background process) by setting the flag to
* suspend writes to stderr, so that we can be stopped and backgrounded * suspend writes to stderr, to stop the terminal being interfered with when
* without messing up the terminal. On a subsequent SIGCONT we will try * pv is stopped and put into the background. On a subsequent SIGCONT, pv
* writing to the terminal again, in case we get backgrounded and later get * will try writing to the terminal again, in case it was put into the
* foregrounded again. * background and later put into the foreground again.
* *
* When we get backgrounded and cause a SIGTTOU, the rest of the pipeline * When a SIGTTOU is raised, the rest of the pipeline gets stopped too, so
* gets stopped too, so transfers involving pipelines need us to send a * transfers involving pipelines need pv to send a SIGCONT to the rest of
* SIGCONT to the rest of the process group here, otherwise backgrounding * the process group here, otherwise backgrounding stops transfers involving
* stops transfers involving pipes. * pipes.
*/ */
static void pv_sig_ttou( /*@unused@ */ __attribute__((unused)) static void pv_sig_ttou( /*@unused@ */ __attribute__((unused))
int s) int s)
@@ -157,8 +157,8 @@ static void pv_sig_cont( /*@unused@ */ __attribute__((unused))
pv_sig_state->flags.terminal_resized = 1; pv_sig_state->flags.terminal_resized = 1;
/* /*
* We can only make the time adjustments if this SIGCONT followed a * Time adjustments can only be made if this SIGCONT followed a
* SIGTSTP such that we have a stop time. * SIGTSTP, such that there is a stop-time to measure from.
*/ */
if (0 != pv_sig_state->signal.when_tstp_arrived.tv_sec) { if (0 != pv_sig_state->signal.when_tstp_arrived.tv_sec) {
@@ -167,10 +167,10 @@ static void pv_sig_cont( /*@unused@ */ __attribute__((unused))
pv_elapsedtime_read(&current_time); pv_elapsedtime_read(&current_time);
/* time spent stopped = current time - time SIGTSTP received */ /* time spent stopped = current time - time SIGTSTP received. */
pv_elapsedtime_subtract(&time_spent_stopped, &current_time, &(pv_sig_state->signal.when_tstp_arrived)); pv_elapsedtime_subtract(&time_spent_stopped, &current_time, &(pv_sig_state->signal.when_tstp_arrived));
/* add time spent stopped the total stopped-time count */ /* add time spent stopped to the total stopped-time count. */
pv_elapsedtime_add(&(pv_sig_state->signal.total_stoppage_time), pv_elapsedtime_add(&(pv_sig_state->signal.total_stoppage_time),
&(pv_sig_state->signal.total_stoppage_time), &time_spent_stopped); &(pv_sig_state->signal.total_stoppage_time), &time_spent_stopped);
@@ -204,13 +204,13 @@ static void pv_sig_cont( /*@unused@ */ __attribute__((unused))
} }
} }
/* reset the SIGTSTP receipt time */ /* reset the SIGTSTP receipt time. */
pv_elapsedtime_zero(&(pv_sig_state->signal.when_tstp_arrived)); pv_elapsedtime_zero(&(pv_sig_state->signal.when_tstp_arrived));
} }
/* /*
* Try resuming our use of stderr, if we had suspended it, but only * Try resuming the use of stderr, if it had been suspended, but
* if we're now in the foreground. * only if pv is now in the foreground.
*/ */
if (1 == pv_sig_state->flags.suspend_stderr) { if (1 == pv_sig_state->flags.suspend_stderr) {
if (pv_in_foreground()) { if (pv_in_foreground()) {
@@ -258,8 +258,8 @@ static void pv_sig_term( /*@unused@ */ __attribute__((unused))
#ifdef PV_REMOTE_CONTROL #ifdef PV_REMOTE_CONTROL
/* /*
* Handle a SIGUSR2 by setting a flag to say we received it, after recording * Handle a SIGUSR2 by recording the PID that sent it, and setting a flag to
* the sending PID. * say it was received.
*/ */
static void pv_sig_usr2( /*@unused@ */ __attribute__((unused)) static void pv_sig_usr2( /*@unused@ */ __attribute__((unused))
int sig, siginfo_t *info, /*@unused@ */ __attribute__((unused)) int sig, siginfo_t *info, /*@unused@ */ __attribute__((unused))
@@ -292,8 +292,8 @@ bool pv_sigusr2_received(pvstate_t state, pid_t *pid)
/* /*
* Handle a SIGUSR1 by setting a flag to say we received it, after recording * Handle a SIGUSR1 by recording the PID that sent it, and setting a flag to
* the sending PID. * say it was received.
*/ */
static void pv_sig_usr1( /*@unused@ */ __attribute__((unused)) static void pv_sig_usr1( /*@unused@ */ __attribute__((unused))
int sig, siginfo_t *info, /*@unused@ */ __attribute__((unused)) int sig, siginfo_t *info, /*@unused@ */ __attribute__((unused))
@@ -330,10 +330,10 @@ bool pv_sigusr1_received(pvstate_t state, pid_t *pid)
/* /*
* Handle alarm signals by doing nothing. * Handle alarm signals by doing nothing.
* *
* Note that we have to use a signal handler like this, instead of using * An empty signal handler is used, instead of SIG_IGN, because ignoring the
* SIG_IGN, because if we ignore the signal entirely, it does nothing, * signal with SIG_IGN prevents it from doing anything at all - meaning it
* including not interrupting blocking write() calls - which is what we're * would not interrupt blocking write() calls, which is what pv uses alarm
* using alarm signals for in the first place. * signals for.
*/ */
static void pv_sig_alrm( /*@unused@ */ __attribute__((unused)) static void pv_sig_alrm( /*@unused@ */ __attribute__((unused))
int s) int s)
@@ -353,10 +353,10 @@ void pv_sig_init(pvstate_t state)
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
/* /*
* Note that wherever we use a "struct sigaction", we declare it * Wherever a "struct sigaction" is used, it is declared static and
* static and explicitly zero it before use, because it may contain * explicitly zeroed before use, because it may contain deeper
* deeper structures (e.g. "sigset_t") which trigger splint * structures (e.g. "sigset_t") which trigger splint warnings about
* warnings about potential memory leaks. * potential memory leaks.
*/ */
pv_sig_state = state; pv_sig_state = state;
@@ -366,14 +366,14 @@ void pv_sig_init(pvstate_t state)
pv_elapsedtime_zero(&(pv_sig_state->signal.total_stoppage_time)); pv_elapsedtime_zero(&(pv_sig_state->signal.total_stoppage_time));
/* /*
* Note that we cast all sigemptyset() and sigaction() return values * All sigemptyset() and sigaction() return values are ignored, as
* to void, because there's nothing we can reasonably do about any * there is no reasonable action to take about any error they
* conceivable error they may return. * return.
*/ */
/* /*
* Ignore SIGPIPE, so we don't die if the output is a pipe and the * Ignore SIGPIPE, in case the output is a pipe and the other end
* other end closes unexpectedly. * closes unexpectedly.
*/ */
sa.sa_handler = SIG_IGN; sa.sa_handler = SIG_IGN;
(void) sigemptyset(&(sa.sa_mask)); (void) sigemptyset(&(sa.sa_mask));
@@ -381,8 +381,9 @@ void pv_sig_init(pvstate_t state)
(void) sigaction(SIGPIPE, &sa, &(pv_sig_state->signal.old_sigpipe)); (void) sigaction(SIGPIPE, &sa, &(pv_sig_state->signal.old_sigpipe));
/* /*
* Handle SIGTTOU by continuing with output switched off, so that we * Handle SIGTTOU by continuing with the display switched off, to
* can be stopped and backgrounded without messing up the terminal. * allow pv to be stopped and backgrounded without messing up the
* terminal.
*/ */
pv_sig_state->flags.skip_next_sigcont = 0; pv_sig_state->flags.skip_next_sigcont = 0;
sa.sa_handler = pv_sig_ttou; sa.sa_handler = pv_sig_ttou;
@@ -469,13 +470,13 @@ void pv_sig_init(pvstate_t state)
/* /*
* Ensure that the TOSTOP terminal attribute is set, so that a * Ensure that the TOSTOP terminal attribute is set, so that a
* SIGTTOU signal will be raised if we try to write to the terminal * SIGTTOU signal will be raised if pv attempts to write to the
* while backgrounded (see the SIGTTOU handler above). * terminal while backgrounded (see the SIGTTOU handler above).
*/ */
pv_sig_ensure_tty_tostop(); pv_sig_ensure_tty_tostop();
/* /*
* Handle SIGALRM by doing nothing, so we can use alarms or interval * Handle SIGALRM by doing nothing, allowing alarms or interval
* timers to interrupt blocking writes (returning EINTR). * timers to interrupt blocking writes (returning EINTR).
*/ */
sa.sa_handler = pv_sig_alrm; sa.sa_handler = pv_sig_alrm;
@@ -486,10 +487,10 @@ void pv_sig_init(pvstate_t state)
/* /*
* Shut down signal handling. If we had set the TOSTOP terminal attribute, * Shut down signal handling. If this pv had set the TOSTOP terminal
* and we're in the foreground, also turn that off (though if we're in * attribute, and is in the foreground, also turn that off (with the
* cursor "-c" mode, only do that if we're the last PV instance, otherwise * restriction that if in cursor "-c" mode, only do that if this is the last
* leave the terminal alone). * PV instance, otherwise leave the terminal alone).
*/ */
void pv_sig_fini( /*@unused@ */ __attribute__((unused)) pvstate_t state) void pv_sig_fini( /*@unused@ */ __attribute__((unused)) pvstate_t state)
{ {
@@ -519,10 +520,10 @@ void pv_sig_fini( /*@unused@ */ __attribute__((unused)) pvstate_t state)
if (pv_sig_state->control.cursor) { if (pv_sig_state->control.cursor) {
#ifdef HAVE_IPC #ifdef HAVE_IPC
/* /*
* We won't clear TOSTOP if other "pv -c" instances * Don't clear TOSTOP if other "pv -c" instances were still
* were still running when pv_crs_fini() ran. * running when pv_crs_fini() ran.
* *
* TODO: we need a better way to determine if we're the last * TODO: find a better way to determine if this is the last
* "pv" left. * "pv" left.
*/ */
if (pv_sig_state->control.cursor && pv_sig_state->cursor.pvcount > 1) { if (pv_sig_state->control.cursor && pv_sig_state->cursor.pvcount > 1) {
@@ -530,9 +531,9 @@ void pv_sig_fini( /*@unused@ */ __attribute__((unused)) pvstate_t state)
} }
#else /* !HAVE_IPC */ #else /* !HAVE_IPC */
/* /*
* Without IPC we can't tell whether the other "pv -c" * Without IPC there's no way to tell whether other "pv -c"
* instances in the pipeline have finished so we will just * instances in the pipeline have finished, so clear TOSTOP
* have to clear TOSTOP anyway. * anyway.
*/ */
#endif /* !HAVE_IPC */ #endif /* !HAVE_IPC */
} }
@@ -599,9 +600,10 @@ void pv_sig_allowpause(void)
/* /*
* If we have suspended stderr, check every second or so to see whether we * If output to stderr is suspended, check once a second whether it is safe
* can write to the terminal again - this is so that if we get backgrounded, * to write to the terminal. This is so that if pv is put into the
* then foregrounded again, we start writing to the terminal again. * background, and then brought into the foreground again, it can resume
* terminal output.
*/ */
void pv_sig_checkbg(void) void pv_sig_checkbg(void)
{ {