Skip to content

Commit

Permalink
Make xclip exit when it loses the selection (#71)
Browse files Browse the repository at this point in the history
Fix issue #64 (#64).

When receiving a SelectionClear event (i.e; lose the selection), the while loop for checking
dloop as-is ran endlessly if sloop is set to -1 (a.k.a unlimited number of requests).
This caused xclip fail to exit when it loses the selection.

Fix the problem via checking whether there is any in-progress transfer. If no, force xclip exit.

Add a test case in xctest to make sure xclip can exit properly. (credit: hackerb9)
  • Loading branch information
hwangcc23 authored and astrand committed Oct 17, 2019
1 parent 040c6af commit 8d10aec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions xclip.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ doIn(Window win, const char *progname)
See ICCCM section 2.2.
Set dloop to sloop for forcing exit after all transfers are completed. */
dloop = sloop;
/* if there is no more in-progress transfer, force exit */
if (!requestors) {
return EXIT_SUCCESS;
}
continue;
} else {
continue;
Expand Down
13 changes: 13 additions & 0 deletions xctest
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ do
esac
done

echo "Testing whether xclip exits correctly when the selection is lost"
echo hello | ./xclip -q -i 2>/dev/null &
sleep 1
echo goodbye | ./xclip -i
sleep 1
if ps $! > /dev/null; then
echo "FAIL: Zombie xclip yet lives! Killing."
killall xclip
exit 1
else
echo "PASS: xclip exited correctly after losing selection"
fi

# test xclip on different amounts of data to bring out any errors
for lines in 2 16 128 1024 8192
do
Expand Down

0 comments on commit 8d10aec

Please sign in to comment.