From 1ba53eead1ab9787e77dc43196b8402ec96e7fd4 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 23 Feb 2021 14:24:19 -0800 Subject: dd: simplify signal handling and fix status output. Other dd implementations always show the status on exit, whether success or failure. Fix that by using xsigatexit() (and clarify the comment for that function a little, since it didn't previously address the "at exit" part of its behavior at all). This also fixes SIGUSR1 behavior so that we show the status immediately rather than on the next trip round the read/write loop. Tested with `dd of=/dev/full`, sending SIGUSR1 twice from another shell (to see the status immediately each time, without exiting), then hitting ^C (to see the status and then exiting), then restarting dd and hitting enter (to see a write error followed by the status before exiting). Bug: https://issuetracker.google.com/177017283 --- lib/lib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/lib.c b/lib/lib.c index 06e39169..87bda4f6 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -911,9 +911,10 @@ void exit_signal(int sig) xexit(); } -// Install the same handler on every signal that defaults to killing the -// process, calling the handler on the way out. Calling multiple times -// adds the handlers to a list, to be called in order. +// Install an atexit handler. Also install the same handler on every signal +// that defaults to killing the process, calling the handler on the way out. +// Calling multiple times adds the handlers to a list, to be called in LIFO +// order. void sigatexit(void *handler) { struct arg_list *al = 0; -- cgit v1.2.3