[PATCH v3 02/19] util: ignore EACCESS in virDirOpenIfExists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>

Whether a directory exists or is not readable shouldn't make a big
diffence.

This removes errors when firmare or vhost-user config is looked up
from a user session libvirt if /etc/libvirt is not readable.

Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
 src/util/virfile.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 81a3c096eb..e830a9ca10 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2833,7 +2833,8 @@ virFileRemove(const char *path,
 #endif /* WIN32 */
 
 static int
-virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT, bool quiet)
+virDirOpenInternal(DIR **dirp, const char *name,
+                   bool ignoreENOENT, bool ignoreEACCESS, bool quiet)
 {
     *dirp = opendir(name); /* exempt from syntax-check */
     if (!*dirp) {
@@ -2842,6 +2843,8 @@ virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT, bool quiet)
 
         if (ignoreENOENT && errno == ENOENT)
             return 0;
+        if (ignoreEACCESS && errno == EACCES)
+            return 0;
         virReportSystemError(errno, _("cannot open directory '%s'"), name);
         return -1;
     }
@@ -2859,7 +2862,7 @@ virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT, bool quiet)
 int
 virDirOpen(DIR **dirp, const char *name)
 {
-    return virDirOpenInternal(dirp, name, false, false);
+    return virDirOpenInternal(dirp, name, false, false, false);
 }
 
 /**
@@ -2868,13 +2871,13 @@ virDirOpen(DIR **dirp, const char *name)
  * @name: path of the directory
  *
  * Returns 1 on success.
- * If opendir returns ENOENT, 0 is returned without reporting an error.
+ * If opendir returns ENOENT or EACCES, 0 is returned without reporting an error.
  * On other errors, -1 is returned and an error is reported.
  */
 int
 virDirOpenIfExists(DIR **dirp, const char *name)
 {
-    return virDirOpenInternal(dirp, name, true, false);
+    return virDirOpenInternal(dirp, name, true, true, false);
 }
 
 /**
@@ -2890,7 +2893,7 @@ virDirOpenIfExists(DIR **dirp, const char *name)
 int
 virDirOpenQuiet(DIR **dirp, const char *name)
 {
-    return virDirOpenInternal(dirp, name, false, true);
+    return virDirOpenInternal(dirp, name, false, false, true);
 }
 
 /**
-- 
2.23.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux