[libvirt] [PATCH 09/17] nss: remove use for virDir helper APIs

Daniel P. Berrangé berrange at redhat.com
Thu Aug 1 15:00:11 UTC 2019


Use the plain libc APIs to avoid a dependancy on the main libvirt
code from the nss module.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 cfg.mk                  |  2 +-
 tools/nss/libvirt_nss.c | 13 +++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index ec09550b49..f2b326ec94 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1338,7 +1338,7 @@ exclude_file_name_regexp--sc_prohibit_always-defined_macros = \
   ^tests/virtestmock.c$$
 
 exclude_file_name_regexp--sc_prohibit_readdir = \
-  ^tests/(.*mock|virfilewrapper)\.c$$
+  ^(tests/(.*mock|virfilewrapper)\.c|tools/nss/libvirt_nss\.c)$$
 
 exclude_file_name_regexp--sc_prohibit_cross_inclusion = \
   ^(src/util/virclosecallbacks\.h|src/util/virhostdev\.h)$$
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index 519046a4e0..f50dec48ba 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -281,7 +281,8 @@ findLease(const char *name,
         goto cleanup;
     }
 
-    if (virDirOpenQuiet(&dir, leaseDir) < 0) {
+    dir = opendir(leaseDir);
+    if (!dir) {
         ERROR("Failed to open dir '%s'", leaseDir);
         goto cleanup;
     }
@@ -292,7 +293,7 @@ findLease(const char *name,
     }
 
     DEBUG("Dir: %s", leaseDir);
-    while ((ret = virDirRead(dir, &entry, leaseDir)) > 0) {
+    while ((entry = readdir(dir)) != NULL) {
         char *path;
 
         if (virStringHasSuffix(entry->d_name, ".status")) {
@@ -324,8 +325,11 @@ findLease(const char *name,
             nMacmaps++;
             VIR_FREE(path);
         }
+
+        errno = 0;
     }
-    VIR_DIR_CLOSE(dir);
+    closedir(dir);
+    dir = NULL;
 
     nleases = virJSONValueArraySize(leases_array);
     DEBUG("Read %zd leases", nleases);
@@ -363,7 +367,8 @@ findLease(const char *name,
 
  cleanup:
     *errnop = errno;
-    VIR_DIR_CLOSE(dir);
+    if (dir)
+        closedir(dir);
     while (nMacmaps)
         virObjectUnref(macmaps[--nMacmaps]);
     return ret;
-- 
2.21.0




More information about the libvir-list mailing list