Scott D wrote:
Hmmm, maybe we don't need a separate exit code if ddrescue was
terminated. Found some really useful information at
http://www.cons.org/cracauer/sigint.html. Try out the following bash
script, editing for your proper ddrescue command:
#!/bin/bash
trap 'echo ddrescue was terminated by the user; exit' 2
ddrescue -f /dev/sdc /dev/null -s 1G
echo ddrescue exited normally
exit
The site is very useful indeed, but your proposed script is of type
"immediate unconditional exit", which leaves ddrescue:
"in an unusable state, since the death of its calling shell will leave
it without required resources (file descriptors). This way does not
work at all for shellscripts that call programs that use SIGINT for
other purposes than immediate exit. Even for programs that exit on
SIGINT, but want to do some cleanup between the signal and the exit,
may fail before they complete their cleanup".
The following script is of type "wait and unconditional exit", and
alows ddrescue to terminate before exiting:
#!/bin/bash
interrupted=no
trap 'interrupted=yes' 2
ddrescue -f /dev/zero /dev/null -s 1G
if [ ${interrupted} = yes ] ; then
echo "ddrescue was terminated by the user" ; exit 130
fi
echo "ddrescue exited normally"
I'll give myself some time to think about the consequences of making
ddrescue exit by raising SIGINT when the user hits Ctrl-C. Doing this
would solve this use case, but it may break others.
Feedback is welcome. :-)
_______________________________________________
Bug-ddrescue mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/bug-ddrescue