On 20 September 2011 21:29, Vincent Lefevre <[email protected]> wrote:
>
> On 2011-09-03 15:27:23 +1000, Cam Hutchison wrote:
> > xpdf's wrapper script should start xpdf.real using 'exec', since it is
> > the last thing the script does. This means an extra process is not kept
> > running, and the process will respond properly to signals.
>
> Because of the trap, using exec in the else case is invalid.
> I've reported another bug about that (but the BTS seems very
> slow to take it into account... the title is "on a compressed
> file, xpdf no longer removes the temporary file due to exec").
>
> Though uncompressed files could be treated separately, I don't
> think it would be a good idea to have a different behavior just
> for them (in particular because compressed files are more and
> more common).
This can be fixed with a construct like this:
case "$file" in
*.gz|*.Z) zcat "$file" > "$tmp" ; exec 3< "$tmp" ; rm "$tmp" ;
tmp=/dev/fd/3 ;;
esac
That is, open the file on fd 3, remove the file and pass /dev/fd/3 as
the fd to xpdf.real. I've tested this with xpdf.real and it works.
You'll want to refactor that a bit to account for errors and remove
the duplication when you expand this to the three different
decompressors.
Can't help myself. Patch attached. Tested with foo.pdf and foo.pdf.gz
[1mdiff --git a/debian/scripts/xpdf b/debian/scripts/xpdf[m
[1mindex 5b0728c..60532e6 100755[m
[1m--- a/debian/scripts/xpdf[m
[1m+++ b/debian/scripts/xpdf[m
[36m@@ -56,13 +56,24 @@[m [mif [ "$many" != "" ]; then[m
elif [ "$file" = "" ]; then[m
exec $cmd -title "$title"[m
else[m
[31m- tmp=$(tempfile -s .pdf)[m
[31m- trap "rm -f -- \"$tmp\"" EXIT HUP INT QUIT TERM [m
case "$file" in[m
[31m- *.gz|*.Z) zcat "$file" > "$tmp" ;;[m
[31m- *.xz) xzcat "$file" > "$tmp" ;;[m
[31m- *.bz2) bzcat "$file" > "$tmp" ;;[m
[31m- *) tmp="$file" ;;[m
[32m+[m[32m *.gz|*.Z) decomp=zcat ;;[m
[32m+[m[32m *.xz) decomp=xzcat ;;[m
[32m+[m[32m *.bz2) decomp=bzcat ;;[m
esac[m
[31m- exec $cmd -title "$title" "$tmp" $pages || true[m
[32m+[m
[32m+[m[32m if [ -n "$decomp" ] ; then[m
[32m+[m[32m tmp=$(tempfile -s .pdf)[m
[32m+[m[32m if $decomp "$file" > "$tmp" ; then[m
[32m+[m[32m exec 3< "$tmp"[m
[32m+[m[32m rm "$tmp"[m
[32m+[m[32m file=/dev/fd/3[m
[32m+[m[32m else[m
[32m+[m[32m echo "Failed to decompress $file" >&2[m
[32m+[m[32m rm "$tmp"[m
[32m+[m[32m exit 1[m
[32m+[m[32m fi[m
[32m+[m[32m fi[m
[32m+[m
[32m+[m[32m exec $cmd -title "$title" "$file" $pages[m
fi[m