Re: git: 5807f35c541c - main - dd: Fix SIGINT handling.

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Fri, 05 May 2023 18:21:36 UTC
On Fri, May 05, 2023 at 12:45:23PM +0000, Dag-Erling Smørgrav wrote:
> The branch main has been updated by des:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=5807f35c541c26bbd91a3ae12506cd8dd8f20688
> 
> commit 5807f35c541c26bbd91a3ae12506cd8dd8f20688
> Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
> AuthorDate: 2023-05-05 11:17:44 +0000
> Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
> CommitDate: 2023-05-05 12:42:32 +0000
> 
>     dd: Fix SIGINT handling.
>     
>     Currently, we handle SIGINT by calling summary() and _exit() directly from the signal handler, which we install after setup().  There are several issues with this:
>     
>     * summary() is not signal safe;
>     * the parent is not informed about the signal;
>     * setup() can block on open(), and catching SIGINT at that stage will produce the correct exit status but will not print anything to stderr as POSIX demands.
>     
>     Fix this by making SIGINT non-restartable, changing our signal handler to only set a flag, installing it before setup(), and checking the termination flag before and after every blocking operation, i.e. open(), read(), write().
>     
>     Also add two test cases, one for catching SIGINT while opening the input and one for catching it while reading.  I couldn't think of an easy way to test catching SIGINT while writing (it's certainly feasible, but perhaps not from a shell script).
>     

This does not fix SIGINT handler, it only (significantly) reduces the window
where the issue could occur.  See my latest comment on the review.