[pacman-dev] [PATCH 08/11] handle_unlock: log error when lock file is missing
Problems due to concurrent running instances of pacman can be difficult to diagnose. Log a warning to make it more obvious that that's what happened, that it's a bad idea, and hopefully encourage people who do things like removing the lock file to run pacman from an install script to at least be courteous enough to put it back when they're done. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- Example convoluted error due to concurrent instances: https://bbs.archlinux.org/viewtopic.php?id=184122 Example install script manually removing the lock file: https://github.com/manjaro/packages-core/blob/master/manjaro-system/manjaro-... lib/libalpm/handle.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 234fc4d..0efc0a9 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -125,12 +125,20 @@ int _alpm_handle_unlock(alpm_handle_t *handle) close(handle->lockfd); handle->lockfd = -1; - if(unlink(handle->lockfile) && errno != ENOENT) { - _alpm_log(handle, ALPM_LOG_WARNING, - _("could not remove lock file %s\n"), handle->lockfile); - alpm_logaction(handle, ALPM_CALLER_PREFIX, - "warning: could not remove lock file %s\n", handle->lockfile); - return -1; + if(unlink(handle->lockfile) != 0) { + if(errno == ENOENT) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("lock file missing %s\n"), handle->lockfile); + alpm_logaction(handle, ALPM_CALLER_PREFIX, + "warning: lock file missing %s\n", handle->lockfile); + return 0; + } else { + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not remove lock file %s\n"), handle->lockfile); + alpm_logaction(handle, ALPM_CALLER_PREFIX, + "warning: could not remove lock file %s\n", handle->lockfile); + return -1; + } } return 0; } -- 2.0.2
On 02/08/14 07:19, Andrew Gregory wrote:
Problems due to concurrent running instances of pacman can be difficult to diagnose. Log a warning to make it more obvious that that's what happened, that it's a bad idea, and hopefully encourage people who do things like removing the lock file to run pacman from an install script to at least be courteous enough to put it back when they're done.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> ---
Example convoluted error due to concurrent instances: https://bbs.archlinux.org/viewtopic.php?id=184122
Example install script manually removing the lock file: https://github.com/manjaro/packages-core/blob/master/manjaro-system/manjaro-...
:headshakes: Acked the patch.
participants (2)
-
Allan McRae
-
Andrew Gregory