-1
[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")

StoneThrow
  • 5,314
  • 4
  • 44
  • 86
  • You'll need the `-f` argument to strace to follow into subprocesses. – Charles Duffy Jan 03 '19 at 03:45
  • (and yes, as implied by the message, using `-z` causes `gzip` to run. Can you still get that exit status with just `cf` instead of `czf`? If not, that implies *very* strongly that you should be narrowing your focus to gzip) – Charles Duffy Jan 03 '19 at 03:46
  • 1
    BTW, `xargs tar` is probably a bad idea in general. What happens if you have more filenames than `xargs` can put onto a single `tar` command's command-line argument list? (Answer: It runs `tar` a *second* time, and overwrites the output file written by the first invocation). `tar` can take a list of files on stdin itself; there's no reason to couple it with `xargs`, and plenty of reason not to. – Charles Duffy Jan 03 '19 at 03:51

1 Answers1

4

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.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441