[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-tar] --exclude-from using process substitution fails
From: |
Helmut Waitzmann |
Subject: |
Re: [Bug-tar] --exclude-from using process substitution fails |
Date: |
Tue, 03 Apr 2007 21:39:00 +0200 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux) |
Paul Eggert <address@hidden> writes:
>"Sergey Poznyakoff" <address@hidden> writes:
>
>> * src/tar.c (main): Move closeopen after decode_options to
>> allow shell process substitution to work.
>
>Out of curiosity, why bother to close all the open file descriptors?
>It sounds like a recipe for further problems. Also, it consumes a bit
>of time.
Not only sounds it like a recipe for further problems, it will cause
further problems.
It's not a good idea to have tar close all open file descriptors, rather
than to let tar close only those open file descriptors that it opened by
itself.
Imagine, one might use some file compressing utility ("my_compress"),
which logs some report on standard error when compressing or
uncompressing the tape archive.
But one doesn't want the compressing log to be mixed with gnu tar's
standard error output.
One way to solve this problem would be to use a wrapper script for the
compressing utility:
---cut-here---
#!/bin/sh
#
# my_compress_wrapper, a wrapper script for the compressing utility,
# which sends stderr to file descriptor no. 3.
#
# redirect stderr to file descriptor no. 3 and execute:
exec my_compress ${1+"$@"} 2>&3 3>&-
---cut-here---
Then use gnu tar like this:
tar --compress my_compress_wrapper ... 3> compress.log
Now, if tar closes fd no. 3, it will break "my_compress_wrapper".
Moreover, if tar then opens a file for writing (may be the snapshot file
or a file to be extracted), using that file descriptor, "my_compress"
will corrupt that file.
Note:
It is not a workaround to let the wrapper script open the log
file, because it can't know which file the log should go into.
And you can't supply an additional parameter, which names the log file,
to the wrapper script, because you can't tell gnu tar to supply that
parameter when it calls the wrapper script.
So, if tar wants to save file descriptors, it should record each file
descriptor number when opening it, then, when it comes to the need of
closing file descriptors, tar could look for open file descriptors in its
recorded list, thereby abstaining from closing file descriptors that are
used by "my_compress".
All file descriptors that are inherited from tar's parent process are
nothing to tar.
--
Wer mir E-Mail schreiben will, stelle | When writing me e-mail, please
bitte vor meine E-Mail-Adresse meinen | precede my e-mail address with
Vor- und Nachnamen, etwa so: | my full name, like
Helmut Waitzmann <address@hidden>, (Helmut Waitzmann) address@hidden