linuxtarreturn-code

Does tar exit code 123 always mean empty archive?


[root@my-pc: ]# printf "" | xargs tar czf ./foo.tgz
tar: empty archive
[root@my-pc: ]# echo $?
123
[root@my-pc: ]# 

The tar man page only documents return codes 0, 1, and 2 but explains further:

If a subprocess that had been invoked by tar exited with a nonzero exit code, tar itself exits with that code as well. This can happen, for example, if a compression option (e.g. -z) was used and the external compressor program failed. Another example is rmt failure during backup to a remote device.

So I assume this return code "123" comes from some invoked subprocess.

Question: Does tar exit code 123 always mean empty archive? (what subprocess returns this code?)

What I have tried:

1) The only thing I could think of was to strace this, but I'm not experienced enough with it to tell if its output reveals the answer to my question.

[root@my-pc: ]# printf "" | xargs strace tar czf ./foo.tgz 2>&1 | grep -w 123

Is the above the correct way to run strace on tar? In any case, the command had no output.

I can include the output of the above without the final grep if relevant, but I'm excluding it for now because it's long, and it's not clear to me that it's necessarily useful

2) Searched SO, the closest hit I found was this, but I'm not sure that that's relevant (not clear to me that find/xargs is involved in the return code of "123")


Solution

  • From man xargs:

    EXIT STATUS
           xargs exits with the following status:
           0 if it succeeds
           123 if any invocation of the command exited with status 1-125
           124 if the command exited with status 255
           125 if the command is killed by a signal
           126 if the command cannot be run
           127 if the command is not found
           1 if some other error occurred.
    

    Thus, any nonzero exit status from tar will cause xargs tar to use status 123.