Project

General

Profile

Bug #8185

get returncode of subshell

Added by exobuzz about 3 years ago. Updated over 1 year ago.

Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
backupninja
Target version:
-
Start date:
10/28/2014
Due date:
% Done:

0%

QA Check:
Ready for QA

Description

backupninja contains the code

         retcode=$?
         # ^^^^^^^^ we have a problem! we can't grab the return code "$?". grrr.

which means there is no way of handling errors from shell scripts. It is possible to get the returncode with bash from ${PIPESTATUS0}. See attached patch which gets the returncode, and adds a fatal error to the bufferfile in the case of a non 0 return (which is very handy for noticing when a shell script has failed). You may want to do more with this, as other logic may have been written because we couldn't get a returncode previously ?

retcode.diff View (624 Bytes) exobuzz, 10/29/2014 12:03 AM

handler-ret-code.patch View - suboptimal & naive implementation (982 Bytes) drzraf, 03/17/2016 11:56 PM

8185-followup-adapt-handlers.patch View (6.85 KB) drzraf, 03/18/2016 12:39 AM


Related issues

Blocks Backupninja - Bug #11246: rdiff-backup success generale notification New 03/16/2016

History

#1 Updated by intrigeri about 3 years ago

  • Assignee deleted (intrigeri)
  • QA Check set to Ready for QA

#2 Updated by drzraf over 1 year ago

Such an important feature waiting in the queue for so long!
I was going to offer the (naive) attached patch when I looked at the issue queue and found exobuzz' patch.
I just tested and it obviously works and it far better.

The only missing bit is to adapt existing handlers to really returns the corresponding value.
I will post a patch for this here, soon (this bug is a real blocker for many things)

Upstream, please push!

#3 Updated by drzraf over 1 year ago

It wasn't with a great pleasure, but I finally did it:
Some particular cases first:
  • sh.in nothing to do
  • sys.in too complex (left to another issue) [it's better, but not mandatory that they all support sending their retcode)
  • rsync.in : impossible. It's run through sh, so no PIPESTATUS, and the `nice rsync` is piped to tee, so $? (which is fed to `check_rsync_exit_status` is the one from `tee` rather than `rsync`). Again please let die /bin/sh
  • maildir: rsync code 24 (file vanished) will means failure even if the script ignore it on purpose
    (side note: touch foo/created is done disregarding the rsync return code)
  • although dsync and maildir was dumb about subshell and return code (fixed on the go)
  • tar.in a small re-indentation happened

Hope it can help this pushed.

#4 Updated by intrigeri over 1 year ago

  • Status changed from New to In Progress

So we need someone else than the author to have a look at the patch, test it and report if it works as intended for them.

#5 Updated by intrigeri over 1 year ago

  • Blocks Bug #11246: rdiff-backup success generale notification added

Also available in: Atom PDF