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: Antonio Diaz Diaz
Subject: Re: [Bug-ddrescue] 2 Suggestions (bi-directional retry and user interruption exit code)
Date: Mon, 17 Feb 2014 16:54:18 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.7.11) Gecko/20050905

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. :-)




reply via email to

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