[dpkg] 114/200: u-a: Use areadlink() instead of lstat() + xreadlink()
Ximin Luo
infinity0 at debian.org
Wed Apr 5 15:17:26 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository dpkg.
commit 3d975af556d69a32db7857d5a4141c5f823ca180
Author: Guillem Jover <guillem at debian.org>
Date: Sun Jan 8 13:33:38 2017 +0100
u-a: Use areadlink() instead of lstat() + xreadlink()
We avoid an lstat() call as we catch the error from areadlink and can
react on that instead of an uncontrolled failure from xreadlink().
---
debian/changelog | 1 +
utils/update-alternatives.c | 11 ++---------
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 4d2d121..91ce6e3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -10,6 +10,7 @@ dpkg (1.18.19) UNRELEASED; urgency=medium
* Always set SOURCE_DATE_EPOCH in dpkg-buildpackage and dpkg-source. Use
the current date if the changelog does not have one. Closes: #849081
* Refactor update-alternatives pathname existence check into a new function.
+ * Avoid useless repeated lstat()s in update-alternatives.
* Portability:
- On GNU/Hurd try to use the new process executable name attribute from
libps, to properly match on start-stop-daemon --exec.
diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 65b9287..9a9d10c 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -1408,7 +1408,6 @@ alternative_set_current(struct alternative *a, char *new_choice)
static const char *
alternative_get_current(struct alternative *a)
{
- struct stat st;
char *curlink;
char *file;
@@ -1416,15 +1415,9 @@ alternative_get_current(struct alternative *a)
return a->current;
curlink = xasprintf("%s/%s", altdir, a->master_name);
- if (lstat(curlink, &st)) {
- if (errno == ENOENT) {
- free(curlink);
- return alternative_set_current(a, NULL);
- }
+ file = areadlink(curlink);
+ if (file == NULL && errno != ENOENT)
syserr(_("cannot stat file '%s'"), curlink);
- }
-
- file = xreadlink(curlink);
free(curlink);
return alternative_set_current(a, file);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list