bug-ddrescue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-ddrescue] 2 Suggestions (bi-directional retry and user interrup


From: Scott D
Subject: Re: [Bug-ddrescue] 2 Suggestions (bi-directional retry and user interruption exit code)
Date: Mon, 17 Feb 2014 19:09:13 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

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
address@hidden
https://lists.gnu.org/mailman/listinfo/bug-ddrescue





reply via email to

[Prev in Thread] Current Thread [Next in Thread]