[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#779608: xvfb: cleanup on signal exits as well



Jérémy Lal:
>> Hello Ximin,
>>
>> i tried your patch, and now when interrupting using ctrl-c
>> xvfb-run -a myapp
>> i get (i added the "cleaning" message):
>>
>> ^Ccleaning /tmp/xvfb-run.UlOS0T
>> cleaning /tmp/xvfb-run.UlOS0T
>> rm: cannot remove '/tmp/xvfb-run.UlOS0T': No such file or directory
>> xvfb-run: error: problem while cleaning up temporary directory
>>
>> obviously cleanup is run twice.
>>

I couldn't figure out why it is run twice [*], but if you just change "rm -r" to "rm -rf" it will no longer fail. I don't see any problem with that.

Updated patch attached, I also updated the signals (added some more, removed KILL since it doesn't actually work) and added some quoting.

X

[*] Ctrl-C sends SIGINT to the whole process group, so I tried with "kill" specifically to the shell running xvfb but it still double-cleaned. I also tried "trap clean_up <signals>" omitting EXIT and adding "clean_up" before "exit" at the bottom of the script but that didn't fix the double-clean either.

-- 
GPG: ed25519/56034877E1F87C35
GPG: rsa4096/1318EFAC5FBBDBCE
git://github.com/infinity0/pubkeys.git
--- /usr/bin/xvfb-run.orig	2016-03-20 15:53:08.182925279 +0100
+++ /usr/bin/xvfb-run	2016-03-20 15:54:31.162849408 +0100
@@ -82,7 +82,7 @@
         XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >>"$ERRORFILE" 2>&1
     fi
     if [ -n "$XVFB_RUN_TMPDIR" ]; then
-        if ! rm -r "$XVFB_RUN_TMPDIR"; then
+        if ! rm -rf "$XVFB_RUN_TMPDIR"; then
             error "problem while cleaning up temporary directory"
             exit 5
         fi
@@ -140,7 +140,7 @@
 fi
 
 # tidy up after ourselves
-trap clean_up EXIT
+trap clean_up EXIT HUP INT QUIT PIPE ALRM TERM
 
 # If the user did not specify an X authorization file to use, set up a temporary
 # directory to house one.
@@ -165,7 +165,7 @@
     XVFBPID=$!
 
     wait || :
-    if kill -0 $XVFBPID 2>/dev/null; then
+    if kill -0 "$XVFBPID" 2>/dev/null; then
         break
     elif [ -n "$AUTONUM" ]; then
         # The display is in use so try another one (if '-a' was specified).
@@ -180,7 +180,7 @@
 
 # Start the command and save its exit status.
 set +e
-DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1
+DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1 & wait "$!"
 RETVAL=$?
 set -e
 

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: