freebsd-dev/bin/dd
Dag-Erling Smørgrav 5807f35c54 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).

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	cracauer, ngie, imp
Differential Revision:	https://reviews.freebsd.org/D39641
2023-05-05 12:42:32 +00:00
..
tests dd: Fix SIGINT handling. 2023-05-05 12:42:32 +00:00
args.c Add O_DIRECT flag to DD for cache bypass 2020-06-04 20:47:11 +00:00
conv_tab.c
conv.c
dd.1 Add O_DIRECT flag to DD for cache bypass 2020-06-04 20:47:11 +00:00
dd.c dd: Fix SIGINT handling. 2023-05-05 12:42:32 +00:00
dd.h Add O_DIRECT flag to DD for cache bypass 2020-06-04 20:47:11 +00:00
extern.h dd: Fix SIGINT handling. 2023-05-05 12:42:32 +00:00
gen.c
Makefile dd: Incorporate some changes from imp for status=progress 2018-08-15 19:46:13 +00:00
Makefile.depend Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
misc.c dd: Fix SIGINT handling. 2023-05-05 12:42:32 +00:00
position.c dd: Fix SIGINT handling. 2023-05-05 12:42:32 +00:00
ref.ascii
ref.ebcdic
ref.ibm
ref.lcase
ref.obs_zeroes
ref.oldascii
ref.oldebcdic
ref.oldibm
ref.pareven
ref.parnone
ref.parodd
ref.parset
ref.swab
ref.ucase