File libvirt-util-rework-error-reporting-in-virGet-User-Group-IDByName.patch of Package libvirt
From add23d6db72a90f707c5cb4c3abd4c1cdc8d5c40 Mon Sep 17 00:00:00 2001
Message-Id: <add23d6db72a90f707c5cb4c3abd4c1cdc8d5c40.1355319681.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 12 Dec 2012 14:31:01 +0100
Subject: [PATCH] util: rework error reporting in virGet(User|Group)IDByName
https://bugzilla.redhat.com/show_bug.cgi?id=883832
This patch gets rid of the undeterministic error reporting code done on
return values of get(pw|gr)nam_r. With this patch, if the group record
is not returned by the corresponding function this error is not
considered fatal even if errno != 0. The error is logged in such case.
(cherry picked from commit 96460a19870d4442b9dae3bb928ea0cd8d455369)
---
src/util/util.c | 50 ++++++++++++++++++--------------------------------
1 file changed, 18 insertions(+), 32 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index 5386540..0fb976d 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -2551,23 +2551,16 @@ virGetUserIDByName(const char *name, uid_t *uid)
}
}
- if (rc != 0) {
- /* We explicitly test for the known error values returned by
- * getpwnam_r as the manpage says:
- * ERRORS
- * 0 or ENOENT or ESRCH or EBADF or EPERM or ...
- * The given name or uid was not found.
- */
- if ((rc == EINTR) || (rc == EIO) || (rc == EMFILE) ||
- (rc == ENFILE) || (rc == ENOMEM)) {
- virReportSystemError(rc, _("Failed to get user record for name '%s'"),
- name);
- goto cleanup;
- }
- }
-
if (!pw) {
- VIR_DEBUG("User record for user '%s' does not exist", name);
+ if (rc != 0) {
+ char buf[1024];
+ /* log the possible error from getpwnam_r. Unfortunately error
+ * reporting from this function is bad and we can't really
+ * rely on it, so we just report that the user wasn't found */
+ VIR_WARN("User record for user '%s' does was not found: %s",
+ name, virStrerror(rc, buf, sizeof(buf)));
+ }
+
ret = 1;
goto cleanup;
}
@@ -2642,23 +2635,16 @@ virGetGroupIDByName(const char *name, gid_t *gid)
}
}
- if (rc != 0) {
- /* We explicitly test for the known error values returned by
- * getgrnam_r as the manpage says:
- * ERRORS
- * 0 or ENOENT or ESRCH or EBADF or EPERM or ...
- * The given name or gid was not found.
- */
- if ((rc == EINTR) || (rc == EIO) || (rc == EMFILE) ||
- (rc == ENFILE) || (rc == ENOMEM)) {
- virReportSystemError(rc, _("Failed to get group record for name '%s'"),
- name);
- goto cleanup;
- }
- }
-
if (!gr) {
- VIR_DEBUG("Group record for group '%s' does not exist", name);
+ if (rc != 0) {
+ char buf[1024];
+ /* log the possible error from getgrnam_r. Unfortunately error
+ * reporting from this function is bad and we can't really
+ * rely on it, so we just report that the user wasn't found */
+ VIR_WARN("Group record for user '%s' does was not found: %s",
+ name, virStrerror(rc, buf, sizeof(buf)));
+ }
+
ret = 1;
goto cleanup;
}
--
1.8.0