On 20 September 2011 21:29, Vincent Lefevre <vinc...@vinc17.net> 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
diff --git a/debian/scripts/xpdf b/debian/scripts/xpdf
index 5b0728c..60532e6 100755
--- a/debian/scripts/xpdf
+++ b/debian/scripts/xpdf
@@ -56,13 +56,24 @@ if [ "$many" != "" ]; then
 elif [ "$file" = "" ]; then
     exec $cmd -title "$title"
 else
-    tmp=$(tempfile -s .pdf)
-    trap "rm -f -- \"$tmp\"" EXIT HUP INT QUIT TERM 
     case "$file" in
-        *.gz|*.Z)  zcat "$file" > "$tmp" ;;
-        *.xz)     xzcat "$file" > "$tmp" ;;
-        *.bz2)    bzcat "$file" > "$tmp" ;;
-        *) tmp="$file" ;;
+        *.gz|*.Z) decomp=zcat ;;
+        *.xz)     decomp=xzcat ;;
+        *.bz2)    decomp=bzcat ;;
     esac
-    exec $cmd -title "$title" "$tmp" $pages || true
+
+    if [ -n "$decomp" ] ; then
+        tmp=$(tempfile -s .pdf)
+        if $decomp "$file" > "$tmp" ; then
+            exec 3< "$tmp"
+            rm "$tmp"
+            file=/dev/fd/3
+        else
+            echo "Failed to decompress $file" >&2
+            rm "$tmp"
+            exit 1
+        fi
+    fi
+
+    exec $cmd -title "$title" "$file" $pages
 fi

Reply via email to