From c4f6c63b5af7d5f91a13770730b2de09ccda0777 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 4 Apr 2013 11:34:29 +0200 Subject: [PATCH] Add a timeout on winexe call so the pre-backup commands cannot hang indefinitely. The version of timeout is only included on RHEL 5 because in EL6, coreutils provides one --- BackupPC-server-scripts.spec | 8 +++++- scripts/timeout | 53 ++++++++++++++++++++++++++++++++++++ scripts/win-post-backup | 7 +++-- scripts/win-pre-backup | 7 +++-- 4 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 scripts/timeout diff --git a/BackupPC-server-scripts.spec b/BackupPC-server-scripts.spec index 2af8301..14242b6 100644 --- a/BackupPC-server-scripts.spec +++ b/BackupPC-server-scripts.spec @@ -35,7 +35,13 @@ Like pre-backup scripts for Windows boxes # Install backup script %{__mkdir_p} $RPM_BUILD_ROOT%{_bindir}/ -%{__install} -m 0755 scripts/* $RPM_BUILD_ROOT%{_bindir}/ +%{__install} -m 0755 scripts/win-* $RPM_BUILD_ROOT%{_bindir}/ + +# coreutils doesn't provides a timeout command in EL5 +# So include the bash one +%if 0%{?rhel} == 5 +%{__install} -m 0755 scripts/timeout $RPM_BUILD_ROOT%{_bindir}/ +%endif # Install conf %{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/BackupPC diff --git a/scripts/timeout b/scripts/timeout new file mode 100644 index 0000000..f0ef034 --- /dev/null +++ b/scripts/timeout @@ -0,0 +1,53 @@ +#Newsgroups: comp.unix.admin,comp.unix.solaris,comp.unix.shell +#From: gwc@root.co.uk (Geoff Clare) +#Subject: Re: timeout -t (Re: How to give rsh a shorter timeout?) +#Message-ID: +#Date: Fri, 13 Feb 1998 18:23:52 GMT + +# +# Conversion to bash v2 syntax done by Chet Ramey &2 ; exit 2 ;; +esac + +( + for t in $timeout $delay + do + while (( $t > $interval )) + do + sleep $interval + kill -0 $$ || exit + t=$(( $t - $interval )) + done + sleep $t + kill $SIG $$ && kill -0 $$ || exit + SIG=-KILL + done +) 2> /dev/null & + +exec "$@" diff --git a/scripts/win-post-backup b/scripts/win-post-backup index 037075a..eb59fc6 100644 --- a/scripts/win-post-backup +++ b/scripts/win-post-backup @@ -9,11 +9,14 @@ if [ ! -z $3 ]; then PASS=$3 fi +# Timeout after 5 minutes +TIMEOUT=300 + BOX=$1 if [[ ! -z $UNAME && ! -z $PASS ]]; then - $WINEXE -s /dev/null -U $UNAME --password=$PASS //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&- + /usr/bin/timeout $TIMEOUT $WINEXE -s /dev/null -U $UNAME --password=$PASS //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&- else - $WINEXE -s /dev/null --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&- + /usr/bin/timeout $TIMEOUT $WINEXE -s /dev/null --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&- fi echo "Rsync and shadow copy unloaded" diff --git a/scripts/win-pre-backup b/scripts/win-pre-backup index 5075bbd..bd1788e 100644 --- a/scripts/win-pre-backup +++ b/scripts/win-pre-backup @@ -7,12 +7,15 @@ if [ ! -z $3 ]; then PASS=$3 fi +# Timeout after 5 minutes +TIMEOUT=300 + BOX=$1 if [[ ! -z $UNAME && ! -z $PASS ]]; then - /usr/bin/winexe -s /dev/null --interactive=0 -U $UNAME --password=$PASS //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255 + /usr/bin/timeout $TIMEOUT /usr/bin/winexe -s /dev/null --interactive=0 -U $UNAME --password=$PASS //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255 else - /usr/bin/winexe -s /dev/null --interactive=0 --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255 + /usr/bin/timeout $TIMEOUT /usr/bin/winexe -s /dev/null --interactive=0 --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255 fi sleep 5 echo "Rsync and shadow copy loaded"