This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=ec3c37f87362cdecbae409b6d24f3c99b09ae0b5 commit ec3c37f87362cdecbae409b6d24f3c99b09ae0b5 Author: Guillem Jover <[email protected]> AuthorDate: Sat Feb 23 04:56:42 2019 +0100 libdpkg, dpkg: Print the dpkg database directory on access errors There were several error messages involving the dpkg database, that were ambiguous by referring to it as "dpkg status area", instead of printing the affected pathname. The historical reason for not being more explicit has been to keep the user a bit under the dark, because this has been an internal database storage, and only those in the known would go there to edit it by hand and similar. This is a bit pointless though, because the Internet is full of references to those directories, and other error messages just print them anyway. In addition, for users that want to diagnose what is the problem this is not helpful, and the directory might have been changed at build or run time with one of the options. Closes: #883700 --- debian/changelog | 2 ++ lib/dpkg/dbmodify.c | 23 +++++++++++++++-------- lib/dpkg/file.c | 13 +++++++------ lib/dpkg/file.h | 4 ++-- lib/dpkg/trigdeferred.c | 5 +++-- src/update.c | 10 +++++++--- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/debian/changelog b/debian/changelog index e40d7f93f..d864d06d2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -36,6 +36,8 @@ dpkg (1.19.5) UNRELEASED; urgency=medium performance at the cost of a bit more memory usage. * libdpkg: Blank packages that are not-installed with unknown selection. Closes: #922410 + * libdpkg, dpkg: Print the dpkg database directory on access errors. + Closes: #883700 * Perl modules: - Dpkg::Vendor::Debian: Add support for merged-usr-via-symlinks tainted tag. Suggested by Alexander E. Patrakov <[email protected]>. diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c index f29c6745f..557dc0eae 100644 --- a/lib/dpkg/dbmodify.c +++ b/lib/dpkg/dbmodify.c @@ -197,7 +197,8 @@ modstatdb_is_locked(void) if (dblockfd == -1) { lockfd = open(lockfile, O_RDONLY); if (lockfd == -1) - ohshite(_("unable to open lock file %s for testing"), lockfile); + ohshite(_("unable to check lock file for dpkg database directory %s"), + dpkg_db_get_dir()); } else { lockfd = dblockfd; } @@ -224,7 +225,8 @@ modstatdb_can_lock(void) if (errno == EACCES || errno == EPERM) return false; else - ohshite(_("unable to open/create frontend lockfile")); + ohshite(_("unable to open/create dpkg frontend lock for directory %s"), + dpkg_db_get_dir()); } } else { frontendlockfd = -1; @@ -235,7 +237,8 @@ modstatdb_can_lock(void) if (errno == EACCES || errno == EPERM) return false; else - ohshite(_("unable to open/create status database lockfile")); + ohshite(_("unable to open/create dpkg database lock file for directory %s"), + dpkg_db_get_dir()); } return true; @@ -245,12 +248,14 @@ void modstatdb_lock(void) { if (!modstatdb_can_lock()) - ohshit(_("you do not have permission to lock the dpkg status database")); + ohshit(_("you do not have permission to lock the dpkg database directory %s"), + dpkg_db_get_dir()); if (frontendlockfd != -1) file_lock(&frontendlockfd, FILE_LOCK_NOWAIT, frontendlockfile, - _("dpkg frontend")); - file_lock(&dblockfd, FILE_LOCK_NOWAIT, lockfile, _("dpkg status database")); + _("dpkg frontend lock")); + file_lock(&dblockfd, FILE_LOCK_NOWAIT, lockfile, + _("dpkg database lock")); } void @@ -282,9 +287,11 @@ modstatdb_open(enum modstatdb_rw readwritereq) case msdbrw_write: case msdbrw_writeifposs: if (access(dpkg_db_get_dir(), W_OK)) { if (errno != EACCES) - ohshite(_("unable to access dpkg status area")); + ohshite(_("unable to access the dpkg database directory %s"), + dpkg_db_get_dir()); else if (readwritereq == msdbrw_write) - ohshit(_("operation requires read/write access to dpkg status area")); + ohshit(_("required read/write access to the dpkg database directory %s"), + dpkg_db_get_dir()); cstatus= msdbrw_readonly; } else { modstatdb_lock(); diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c index a949bd49e..614d969e3 100644 --- a/lib/dpkg/file.c +++ b/lib/dpkg/file.c @@ -118,26 +118,27 @@ file_lock_setup(struct flock *fl, short type) * Unlock a previously locked file. */ void -file_unlock(int lockfd, const char *lock_desc) +file_unlock(int lockfd, const char *lockfile, const char *lockdesc) { struct flock fl; if (lockfd < 0) - internerr("lock fd is %d < 0", lockfd); + internerr("%s (%s) fd is %d < 0", lockdesc, lockfile, lockfd); file_lock_setup(&fl, F_UNLCK); if (fcntl(lockfd, F_SETLK, &fl) == -1) - ohshite(_("unable to unlock %s"), lock_desc); + ohshite(_("unable to unlock %s"), lockdesc); } static void file_unlock_cleanup(int argc, void **argv) { int lockfd = *(int *)argv[0]; - const char *lock_desc = argv[1]; + const char *lockfile = argv[1]; + const char *lockdesc = argv[2]; - file_unlock(lockfd, lock_desc); + file_unlock(lockfd, lockfile, lockdesc); } /** @@ -194,7 +195,7 @@ file_lock(int *lockfd, enum file_lock_flags flags, const char *filename, ohshite(_("unable to lock %s"), desc); } - push_cleanup(file_unlock_cleanup, ~0, 2, lockfd, desc); + push_cleanup(file_unlock_cleanup, ~0, 3, lockfd, filename, desc); } void diff --git a/lib/dpkg/file.h b/lib/dpkg/file.h index 0f46cc07b..ead11c73a 100644 --- a/lib/dpkg/file.h +++ b/lib/dpkg/file.h @@ -60,8 +60,8 @@ enum file_lock_flags { bool file_is_locked(int lockfd, const char *filename); void file_lock(int *lockfd, enum file_lock_flags flags, const char *filename, - const char *desc); -void file_unlock(int fd, const char *desc); + const char *filedesc); +void file_unlock(int fd, const char *filename, const char *filedesc); void file_show(const char *filename); /** @} */ diff --git a/lib/dpkg/trigdeferred.c b/lib/dpkg/trigdeferred.c index 12677ddc9..b9b028f73 100644 --- a/lib/dpkg/trigdeferred.c +++ b/lib/dpkg/trigdeferred.c @@ -83,13 +83,14 @@ trigdef_update_start(enum trigdef_update_flags uf) if (lock_fd == -1) { if (!(errno == ENOENT && (uf & TDUF_NO_LOCK_OK))) ohshite(_("unable to open/create " - "triggers lockfile '%.250s'"), + "triggers lock file '%.250s'"), fn.buf); return TDUS_ERROR_NO_DIR; } } - file_lock(&lock_fd, FILE_LOCK_WAIT, fn.buf, _("triggers area")); + file_lock(&lock_fd, FILE_LOCK_WAIT, fn.buf, + _("triggers database lock")); } constructfn(&fn, triggersdir, TRIGGERSDEFERREDFILE); diff --git a/src/update.c b/src/update.c index fed9b22c9..313f09de9 100644 --- a/src/update.c +++ b/src/update.c @@ -59,11 +59,15 @@ updateavailable(const char *const *argv) } if (!f_noact) { - if (access(dpkg_db_get_dir(), W_OK)) { + const char *dbdir = dpkg_db_get_dir(); + + if (access(dbdir, W_OK)) { if (errno != EACCES) - ohshite(_("unable to access dpkg status area for bulk available update")); + ohshite(_("unable to access dpkg database directory '%s' for bulk available update"), + dbdir); else - ohshit(_("bulk available update requires write access to dpkg status area")); + ohshit(_("required write access to dpkg database directory '%s' for bulk available update"), + dbdir); } modstatdb_lock(); } -- Dpkg.Org's dpkg

