pacman/scripts
Lukas Fleischer d4c97ea2f6 repo-add: Avoid race condition in signal handlers
There is a small chance that a user sends SIGINT (or any other signal
that is trapped) when we're already in clean_up() which used to lead to
trap_exit() being executed and the remaining code in clean_up() being
skipped due to the bash signal/trap handler blocking EXIT (since its
handler is already being executed, even if it's interrupted).

In practice, this behaviour caused unexpected results (primarily because
pressing ^C at the wrong time left a lock file behind):

    $ ./repo-add extra.db.tar.gz foobar
    ==> Extracting database to a temporary location...
    ^C
    ==> ERROR: Aborted by user! Exiting...
    $ ./repo-add extra.db.tar.gz foobar
    ==> Extracting database to a temporary location...
    ==> ERROR: File 'foobar' not found.
    ==> No packages modified, nothing to do.
    ^C
    ==> ERROR: Aborted by user! Exiting...
    $ ./repo-add extra.db.tar.gz foobar
    ==> ERROR: Failed to acquire lockfile: extra.db.tar.gz.lck.
    ==> ERROR: Held by process 18522

Fix this and reduce the chance of race conditions in signal handlers by:

* Unhooking all traps in both clean_up() and trap_exit().

* Call clean_up() explicitly in trap_exit() to make sure we remove the
  lock file and the temporary directory even if we send SIGINT when
  clean_up() is already being executed but didn't reach the unhook code
  yet.

Also, add an optional parameter to clean_up() to allow for setting an
explicit exit code when we call clean_up() from trap_exit().

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Signed-off-by: Dan McGee <dan@archlinux.org>
2011-10-13 11:20:03 -05:00
..
library parse_options: accept multiple arguments 2011-07-05 10:22:31 -05:00
po Final Transifex update before 4.0 2011-10-12 13:42:12 -05:00
.gitignore Move some .gitignore entries 2011-07-18 10:28:19 -05:00
Makefile.am buildsys: remove existing symlinks before installing 2011-09-14 17:18:07 -05:00
makepkg.sh.in makepkg: strip comments after pkgver/pkgrel when checking value 2011-10-10 19:05:22 -05:00
pacman-db-upgrade.sh.in fix vim syntax highlighting of .sh files 2011-06-30 10:44:45 -05:00
pacman-key.sh.in pacman-key: don't escape single quote in usage message 2011-10-11 09:07:20 -05:00
pacman-optimize.sh.in fix vim syntax highlighting of .sh files 2011-06-30 10:44:45 -05:00
pkgdelta.sh.in pkgdelta: proper quoting in [[ expression ]] 2011-09-28 14:09:01 -05:00
rankmirrors.sh.in rankmirrors: properly sort resulting times 2011-09-06 08:44:34 -05:00
repo-add.sh.in repo-add: Avoid race condition in signal handlers 2011-10-13 11:20:03 -05:00