[PATCHv2 3/7] conf: use virDirRead API

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

 



When reading configuration files, we were silently ignoring
directory read failures.  While unlikely, we might as well
report them.

* src/conf/domain_conf.c (virDomainObjListLoadAllConfigs): Report
readdir errors.
* src/conf/network_conf.c (virNetworkLoadAllState)
(virNetworkLoadAllConfigs): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterLoadAllConfigs): Likewise.
* src/conf/storage_conf.c (virStoragePoolLoadAllConfigs):
Likewise.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/conf/domain_conf.c   |  5 +++--
 src/conf/network_conf.c  | 11 ++++++-----
 src/conf/nwfilter_conf.c |  6 +++---
 src/conf/storage_conf.c  |  6 +++---
 4 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c655bcf..0569f66 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18219,6 +18219,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
 {
     DIR *dir;
     struct dirent *entry;
+    int ret = -1;

     VIR_INFO("Scanning for configs in %s", configDir);

@@ -18233,7 +18234,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,

     virObjectLock(doms);

-    while ((entry = readdir(dir))) {
+    while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
         virDomainObjPtr dom;

         if (entry->d_name[0] == '.')
@@ -18273,7 +18274,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,

     closedir(dir);
     virObjectUnlock(doms);
-    return 0;
+    return ret;
 }

 int
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 56c4a09..94ebaf8 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3139,6 +3139,7 @@ virNetworkLoadAllState(virNetworkObjListPtr nets,
 {
     DIR *dir;
     struct dirent *entry;
+    int ret = -1;

     if (!(dir = opendir(stateDir))) {
         if (errno == ENOENT)
@@ -3148,7 +3149,7 @@ virNetworkLoadAllState(virNetworkObjListPtr nets,
         return -1;
     }

-    while ((entry = readdir(dir))) {
+    while ((ret = virDirRead(dir, &entry, stateDir)) > 0) {
         virNetworkObjPtr net;

         if (entry->d_name[0] == '.')
@@ -3162,7 +3163,7 @@ virNetworkLoadAllState(virNetworkObjListPtr nets,
     }

     closedir(dir);
-    return 0;
+    return ret;
 }


@@ -3172,6 +3173,7 @@ int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
 {
     DIR *dir;
     struct dirent *entry;
+    int ret = -1;

     if (!(dir = opendir(configDir))) {
         if (errno == ENOENT)
@@ -3182,7 +3184,7 @@ int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
         return -1;
     }

-    while ((entry = readdir(dir))) {
+    while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
         virNetworkObjPtr net;

         if (entry->d_name[0] == '.')
@@ -3202,8 +3204,7 @@ int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
     }

     closedir(dir);
-
-    return 0;
+    return ret;
 }

 int virNetworkDeleteConfig(const char *configDir,
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index b332f0f..90da0b5 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -3097,6 +3097,7 @@ virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters,
 {
     DIR *dir;
     struct dirent *entry;
+    int ret = -1;

     if (!(dir = opendir(configDir))) {
         if (errno == ENOENT) {
@@ -3107,7 +3108,7 @@ virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters,
         return -1;
     }

-    while ((entry = readdir(dir))) {
+    while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
         char *path;
         virNWFilterObjPtr nwfilter;

@@ -3128,8 +3129,7 @@ virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters,
     }

     closedir(dir);
-
-    return 0;
+    return ret;
 }


diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index ebd42c2..9769b19 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1862,6 +1862,7 @@ virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
 {
     DIR *dir;
     struct dirent *entry;
+    int ret;

     if (!(dir = opendir(configDir))) {
         if (errno == ENOENT)
@@ -1871,7 +1872,7 @@ virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
         return -1;
     }

-    while ((entry = readdir(dir))) {
+    while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
         char *path;
         char *autostartLink;
         virStoragePoolObjPtr pool;
@@ -1901,8 +1902,7 @@ virStoragePoolLoadAllConfigs(virStoragePoolObjListPtr pools,
     }

     closedir(dir);
-
-    return 0;
+    return ret;
 }

 int
-- 
1.9.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]