Bug #8185

get returncode of subshell

Added by exobuzz over 3 years ago. Updated about 2 years ago.

In Progress
Target version:
Start date:
Due date:
% Done:


QA Check:
Ready for QA


backupninja contains the code

         # ^^^^^^^^ 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


#1 Updated by intrigeri over 3 years ago

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

#2 Updated by drzraf about 2 years 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 about 2 years ago

It wasn't with a great pleasure, but I finally did it:
Some particular cases first:
  • nothing to do
  • too complex (left to another issue) [it's better, but not mandatory that they all support sending their retcode)
  • : 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)
  • a small re-indentation happened

Hope it can help this pushed.

#4 Updated by intrigeri about 2 years 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 about 2 years ago

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

Also available in: Atom PDF