I did not realize that, I just sort of through that out since it seemed
to work in testing. I like your method much better! I also did not
realize that the method that I use in C to tell if ddrescue exited by
termination does not work on all systems. I have revised my code to use
WTERMSIG and WEXITSTATUS as opposed to the not so correct slop I had
previously written. It works fine in Ubuntu. But I tested it on Fedora
and on a Mac (in virtual machines), and it doesn't work on them. It
would appear that Ubuntu carries over the WTERMSIG after ddrescue is
terminated, but the other systems do not. So if there is a good way to
tell for sure if ddrescue was terminated by the user (other than reading
the screen), I would be all for it.
Scott
On 2/17/2014 10:54 AM, Antonio Diaz Diaz wrote:
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
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-ddrescue
_______________________________________________
Bug-ddrescue mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-ddrescue