This is going to be important in next commits because we are
going to store more information than just DIR structure.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
build-aux/syntax-check.mk | 2 +-
src/bhyve/bhyve_capabilities.c | 2 +-
src/bhyve/bhyve_firmware.c | 2 +-
src/conf/capabilities.c | 8 +++---
src/conf/virdomainobjlist.c | 2 +-
src/conf/virnetworkobj.c | 8 +++---
src/conf/virnwfilterbindingobjlist.c | 2 +-
src/conf/virnwfilterobj.c | 2 +-
src/conf/virsecretobj.c | 2 +-
src/conf/virstorageobj.c | 4 +--
src/node_device/node_device_udev.c | 2 +-
src/openvz/openvz_conf.c | 2 +-
src/qemu/qemu_domain.c | 2 +-
src/qemu/qemu_driver.c | 4 +--
src/qemu/qemu_interop_config.c | 2 +-
src/security/security_selinux.c | 4 +--
src/storage/storage_backend_iscsi.c | 2 +-
src/storage/storage_util.c | 10 +++----
src/util/vircgroup.c | 4 +--
src/util/vircgroupv1.c | 2 +-
src/util/vircommand.c | 2 +-
src/util/virdevmapper.c | 2 +-
src/util/virfile.c | 40 +++++++++++++++++-----------
src/util/virfile.h | 14 +++++-----
src/util/virhook.c | 4 +--
src/util/virhostcpu.c | 6 ++---
src/util/virmdev.c | 4 +--
src/util/virnetdev.c | 2 +-
src/util/virnuma.c | 2 +-
src/util/virpci.c | 8 +++---
src/util/virprocess.c | 2 +-
src/util/virresctrl.c | 8 +++---
src/util/virscsi.c | 4 +--
src/util/virscsihost.c | 2 +-
src/util/virusb.c | 2 +-
src/util/virutil.c | 4 +--
src/util/virvhba.c | 6 ++---
tests/testutilsqemu.c | 4 +--
tests/virschematest.c | 2 +-
tools/virt-host-validate-common.c | 2 +-
40 files changed, 99 insertions(+), 89 deletions(-)
diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index e1d80bd536..d8fff7bbd6 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -210,7 +210,7 @@ sc_prohibit_gethostname:
sc_prohibit_readdir:
@prohibit='\b(read|close|open)dir *\(' \
exclude='exempt from syntax-check' \
- halt='use virDirOpen, virDirRead and g_autoptr(DIR)' \
+ halt='use virDirOpen, virDirRead and g_autoptr(virDir)' \
$(_sc_search_regexp)
sc_prohibit_gettext_noop:
diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index b065256cf0..3bad78fd56 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -127,7 +127,7 @@ virBhyveDomainCapsBuild(struct _bhyveConn *conn,
{
virDomainCaps *caps = NULL;
unsigned int bhyve_caps = 0;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
size_t firmwares_alloc = 0;
struct _virBhyveDriverConfig *cfg = virBhyveDriverGetConfig(conn);
diff --git a/src/bhyve/bhyve_firmware.c b/src/bhyve/bhyve_firmware.c
index b0f3026c76..75b0311608 100644
--- a/src/bhyve/bhyve_firmware.c
+++ b/src/bhyve/bhyve_firmware.c
@@ -40,7 +40,7 @@ bhyveFirmwareFillDomain(bhyveConn *driver,
virDomainDef *def,
unsigned int flags)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
g_autoptr(virBhyveDriverConfig) cfg = virBhyveDriverGetConfig(driver);
const char *firmware_dir = cfg->firmwareDir;
struct dirent *entry;
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 34770fc416..f9fa90ff48 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1607,7 +1607,7 @@ static int
virCapabilitiesGetNodeCache(int node,
GArray **cachesRet)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int direrr = 0;
struct dirent *entry;
g_autofree char *path = NULL;
@@ -1793,7 +1793,7 @@ virCapabilitiesHostNUMAInitInterconnectsNode(GArray *interconnects,
{
g_autofree char *path = NULL;
g_autofree char *initPath = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int direrr = 0;
struct dirent *entry;
unsigned int read_bandwidth;
@@ -1897,7 +1897,7 @@ virCapsHostNUMAInterconnectComparator(const void *a,
static int
virCapabilitiesHostNUMAInitInterconnects(virCapsHostNUMA *caps)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int direrr = 0;
struct dirent *entry;
const char *path = SYSFS_SYSTEM_PATH "/node/";
@@ -2176,7 +2176,7 @@ virCapabilitiesInitCaches(virCaps *caps)
while ((pos = virBitmapNextSetBit(cpus, pos)) >= 0) {
int rv = -1;
- g_autoptr(DIR) dirp = NULL;
+ g_autoptr(virDir) dirp = NULL;
g_autofree char *path = g_strdup_printf("%s/cpu/cpu%zd/cache/",
SYSFS_SYSTEM_PATH, pos);
g_autoptr(virCapsHostCacheBank) bank = NULL;
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 2569454ff8..528ceee477 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -567,7 +567,7 @@ virDomainObjListLoadAllConfigs(virDomainObjList *doms,
virDomainLoadConfigNotify notify,
void *opaque)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 635d2ec0b0..6d8291eeca 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1043,7 +1043,7 @@ virNetworkObjLoadAllState(virNetworkObjList *nets,
const char *stateDir,
virNetworkXMLOption *xmlopt)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@@ -1077,7 +1077,7 @@ virNetworkObjLoadAllConfigs(virNetworkObjList *nets,
const char *autostartDir,
virNetworkXMLOption *xmlopt)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@@ -1666,7 +1666,7 @@ virNetworkObjDeleteAllPorts(virNetworkObj *net,
const char *stateDir)
{
g_autofree char *dir = NULL;
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
struct dirent *de;
int rc;
@@ -1813,7 +1813,7 @@ virNetworkObjLoadAllPorts(virNetworkObj *net,
const char *stateDir)
{
g_autofree char *dir = NULL;
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
struct dirent *de;
int rc;
char uuidstr[VIR_UUID_STRING_BUFLEN];
diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbindingobjlist.c
index a349f5c195..a82253a6a9 100644
--- a/src/conf/virnwfilterbindingobjlist.c
+++ b/src/conf/virnwfilterbindingobjlist.c
@@ -294,7 +294,7 @@ int
virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjList *bindings,
const char *configDir)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index e8dfe66b3c..477ae93a81 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -611,7 +611,7 @@ int
virNWFilterObjListLoadAllConfigs(virNWFilterObjList *nwfilters,
const char *configDir)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 4929f74155..caa6228983 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -894,7 +894,7 @@ int
virSecretLoadAllConfigs(virSecretObjList *secrets,
const char *configDir)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *de;
int rc;
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 98d9e0b97e..d6cc71c44b 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1662,7 +1662,7 @@ int
virStoragePoolObjLoadAllState(virStoragePoolObjList *pools,
const char *stateDir)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@@ -1690,7 +1690,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjList *pools,
const char *configDir,
const char *autostartDir)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret;
int rc;
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 2454cab8f8..8752d5bc3c 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1176,7 +1176,7 @@ udevGetVDPACharDev(const char *sysfs_path,
virNodeDevCapData *data)
{
struct dirent *entry;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int direrr;
if (virDirOpenIfExists(&dir, sysfs_path) <= 0)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index c28d0e9f43..757365cdda 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -939,7 +939,7 @@ openvzSetUUID(int vpsid)
static int openvzAssignUUIDs(void)
{
- g_autoptr(DIR) dp = NULL;
+ g_autoptr(virDir) dp = NULL;
struct dirent *dent;
char *conf_dir;
int vpsid;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 5c05032ce3..004da783ec 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11839,7 +11839,7 @@ qemuDomainRemoveLogs(virQEMUDriver *driver,
g_autoptr(virQEMUDriverConfig) cfg = NULL;
g_autofree char *format = NULL;
g_autofree char *main_log = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int rc;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d509582719..e7bb9f237a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -332,7 +332,7 @@ qemuDomainSnapshotLoad(virDomainObj *vm,
{
char *baseDir = (char *)data;
g_autofree char *snapDir = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
virDomainMomentObj *snap = NULL;
virDomainMomentObj *current = NULL;
@@ -430,7 +430,7 @@ qemuDomainCheckpointLoad(virDomainObj *vm,
{
char *baseDir = (char *)data;
g_autofree char *chkDir = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
virDomainCheckpointDef *def = NULL;
virDomainMomentObj *chk = NULL;
diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c
index cdc710804f..c3b1e7af75 100644
--- a/src/qemu/qemu_interop_config.c
+++ b/src/qemu/qemu_interop_config.c
@@ -35,7 +35,7 @@ VIR_LOG_INIT("qemu.qemu_configs");
static int
qemuBuildFileList(GHashTable *files, const char *dir)
{
- g_autoptr(DIR) dirp = NULL;
+ g_autoptr(virDir) dirp = NULL;
struct dirent *ent = NULL;
int rc;
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 93cc12407a..9e01874157 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -3456,7 +3456,7 @@ virSecuritySELinuxSetFileLabels(virSecurityManager *mgr,
int ret = 0;
struct dirent *ent;
char *filename = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
if ((ret = virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagelabel, true)))
return ret;
@@ -3500,7 +3500,7 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManager *mgr,
int ret = 0;
struct dirent *ent;
char *filename = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
if ((ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true)))
return ret;
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 968a70158b..bdb38d4ec9 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -87,7 +87,7 @@ static int
virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
uint32_t *host)
{
- g_autoptr(DIR) sysdir = NULL;
+ g_autoptr(virDir) sysdir = NULL;
struct dirent *dirent = NULL;
int direrr;
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 3871718b09..8a8c296faa 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1981,7 +1981,7 @@ virStorageBackendStablePath(virStoragePoolObj *pool,
bool loop)
{
virStoragePoolDef *def = virStoragePoolObjGetDef(pool);
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
struct dirent *dent;
char *stablepath;
int opentries = 0;
@@ -3556,7 +3556,7 @@ int
virStorageBackendRefreshLocal(virStoragePoolObj *pool)
{
virStoragePoolDef *def = virStoragePoolObjGetDef(pool);
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *ent;
struct statvfs sb;
struct stat statbuf;
@@ -3772,7 +3772,7 @@ getNewStyleBlockDevice(const char *lun_path,
const char *block_name G_GNUC_UNUSED,
char **block_device)
{
- g_autoptr(DIR) block_dir = NULL;
+ g_autoptr(virDir) block_dir = NULL;
struct dirent *block_dirent = NULL;
int direrr;
g_autofree char *block_path = NULL;
@@ -3840,7 +3840,7 @@ getBlockDevice(uint32_t host,
uint32_t lun,
char **block_device)
{
- g_autoptr(DIR) lun_dir = NULL;
+ g_autoptr(virDir) lun_dir = NULL;
struct dirent *lun_dirent = NULL;
int direrr;
g_autofree char *lun_path = NULL;
@@ -4003,7 +4003,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObj *pool,
int retval = 0;
uint32_t bus, target, lun;
const char *device_path = "/sys/bus/scsi/devices";
- g_autoptr(DIR) devicedir = NULL;
+ g_autoptr(virDir) devicedir = NULL;
struct dirent *lun_dirent = NULL;
char devicepattern[64];
int found = 0;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 73675b4478..783ca68572 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2573,7 +2573,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroup *group, char **usage)
int
virCgroupRemoveRecursively(char *grppath)
{
- g_autoptr(DIR) grpdir = NULL;
+ g_autoptr(virDir) grpdir = NULL;
struct dirent *ent;
int rc = 0;
int direrr;
@@ -2738,7 +2738,7 @@ virCgroupKillRecursiveInternal(virCgroup *group,
int controller;
bool killedAny = false;
g_autofree char *keypath = NULL;
- g_autoptr(DIR) dp = NULL;
+ g_autoptr(virDir) dp = NULL;
struct dirent *ent;
int direrr;
VIR_DEBUG("group=%p signum=%d pids=%p taskFile=%s dormdir=%d",
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index cbee08e931..68d2778a3b 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -931,7 +931,7 @@ virCgroupV1SetOwner(virCgroup *cgroup,
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
g_autofree char *base = NULL;
struct dirent *de;
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
if (!((1 << i) & controllers))
continue;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 0917bc9cfb..3aa79d68d0 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -487,7 +487,7 @@ static int
virCommandMassCloseGetFDsLinux(virCommand *cmd G_GNUC_UNUSED,
virBitmap *fds)
{
- g_autoptr(DIR) dp = NULL;
+ g_autoptr(virDir) dp = NULL;
struct dirent *entry;
const char *dirName = "/proc/self/fd";
int rc;
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index 7796e7719b..de103902cc 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -171,7 +171,7 @@ virDMSanitizepath(const char *path)
g_autofree char *dmDirPath = NULL;
struct dirent *ent = NULL;
struct stat sb[2];
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
const char *p;
/* If a path is NOT provided then assume it's DM name */
diff --git a/src/util/virfile.c b/src/util/virfile.c
index feb0d7f8ba..ae60be2189 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -793,7 +793,7 @@ static int virFileLoopDeviceOpenLoopCtl(char **dev_name, int *fd)
static int virFileLoopDeviceOpenSearch(char **dev_name)
{
int fd = -1;
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
struct dirent *de;
char *looppath = NULL;
struct loop_info64 lo;
@@ -955,7 +955,7 @@ virFileNBDDeviceIsBusy(const char *dev_name)
static char *
virFileNBDDeviceFindUnused(void)
{
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
struct dirent *de;
int direrr;
@@ -1089,7 +1089,7 @@ int virFileNBDDeviceAssociate(const char *file,
*/
int virFileDeleteTree(const char *dir)
{
- g_autoptr(DIR) dh = NULL;
+ g_autoptr(virDir) dh = NULL;
struct dirent *de;
int direrr;
@@ -2897,11 +2897,16 @@ virFileRemove(const char *path,
}
#endif /* WIN32 */
+struct _virDir {
+ DIR *dir;
+};
+
static int
-virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT, bool quiet)
+virDirOpenInternal(virDir **dirp, const char *name, bool ignoreENOENT, bool quiet)
{
- *dirp = opendir(name); /* exempt from syntax-check */
- if (!*dirp) {
+ DIR *dir = opendir(name); /* exempt from syntax-check */
+
+ if (!dir) {
if (quiet)
return -1;
@@ -2910,6 +2915,9 @@ virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT,
bool quiet)
virReportSystemError(errno, _("cannot open directory '%s'"),
name);
return -1;
}
+
+ *dirp = g_new(virDir, 1);
+ (*dirp)->dir = g_steal_pointer(&dir);
return 1;
}
@@ -2922,7 +2930,7 @@ virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT,
bool quiet)
* On failure, -1 is returned and an error is reported.
*/
int
-virDirOpen(DIR **dirp, const char *name)
+virDirOpen(virDir **dirp, const char *name)
{
return virDirOpenInternal(dirp, name, false, false);
}
@@ -2937,7 +2945,7 @@ virDirOpen(DIR **dirp, const char *name)
* On other errors, -1 is returned and an error is reported.
*/
int
-virDirOpenIfExists(DIR **dirp, const char *name)
+virDirOpenIfExists(virDir **dirp, const char *name)
{
return virDirOpenInternal(dirp, name, true, false);
}
@@ -2953,7 +2961,7 @@ virDirOpenIfExists(DIR **dirp, const char *name)
* Does not report any errors and errno is preserved.
*/
int
-virDirOpenQuiet(DIR **dirp, const char *name)
+virDirOpenQuiet(virDir **dirp, const char *name)
{
return virDirOpenInternal(dirp, name, false, true);
}
@@ -2965,7 +2973,7 @@ virDirOpenQuiet(DIR **dirp, const char *name)
* @name: if non-NULL, the name related to @dirp for use in error reporting
*
* Wrapper around readdir. Typical usage:
- * g_autoptr(DIR) dir = NULL;
+ * g_autoptr(virDir) dir = NULL;
* struct dirent *ent;
* int rc;
* if (virDirOpen(&dir, name) < 0)
@@ -2978,11 +2986,11 @@ virDirOpenQuiet(DIR **dirp, const char *name)
* Returns -1 on error, with error already reported if @name was
* supplied. On success, returns 1 for entry read, 0 for end-of-dir.
*/
-int virDirRead(DIR *dirp, struct dirent **ent, const char *name)
+int virDirRead(virDir *dirp, struct dirent **ent, const char *name)
{
do {
errno = 0;
- *ent = readdir(dirp); /* exempt from syntax-check */
+ *ent = readdir(dirp->dir); /* exempt from syntax-check */
if (!*ent && errno) {
if (name)
virReportSystemError(errno, _("Unable to read directory
'%s'"),
@@ -2994,12 +3002,12 @@ int virDirRead(DIR *dirp, struct dirent **ent, const char *name)
return !!*ent;
}
-void virDirClose(DIR *dirp)
+void virDirClose(virDir *dirp)
{
- if (!dirp)
+ if (!dirp || !dirp->dir)
return;
- closedir(dirp); /* exempt from syntax-check */
+ closedir(dirp->dir); /* exempt from syntax-check */
}
@@ -3020,7 +3028,7 @@ int virFileChownFiles(const char *name,
{
struct dirent *ent;
int direrr;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
if (virDirOpen(&dir, name) < 0)
return -1;
diff --git a/src/util/virfile.h b/src/util/virfile.h
index f7a31d9f57..d4b6b9a15e 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -270,16 +270,18 @@ enum {
};
int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
unsigned int flags) G_GNUC_WARN_UNUSED_RESULT;
-int virDirOpen(DIR **dirp, const char *dirname)
+
+typedef struct _virDir virDir;
+int virDirOpen(virDir **dirp, const char *dirname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
-int virDirOpenIfExists(DIR **dirp, const char *dirname)
+int virDirOpenIfExists(virDir **dirp, const char *dirname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
-int virDirOpenQuiet(DIR **dirp, const char *dirname)
+int virDirOpenQuiet(virDir **dirp, const char *dirname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
-int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname)
+int virDirRead(virDir *dirp, struct dirent **ent, const char *dirname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
-void virDirClose(DIR *dirp);
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(DIR, virDirClose);
+void virDirClose(virDir *dirp);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDir, virDirClose);
int virFileMakeParentPath(const char *path) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/src/util/virhook.c b/src/util/virhook.c
index 871bfcc670..8d1240667e 100644
--- a/src/util/virhook.c
+++ b/src/util/virhook.c
@@ -142,7 +142,7 @@ static int
virHookCheck(int no, const char *driver)
{
int ret;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
g_autofree char *dir_path = NULL;
@@ -333,7 +333,7 @@ virHookCall(int driver,
char **output)
{
int ret, script_ret;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
g_autofree char *dir_path = NULL;
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index c1e8dc8078..b9ff24e9ac 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -296,7 +296,7 @@ virHostCPUParseNode(const char *node,
{
int ret = -1;
int processors = 0;
- g_autoptr(DIR) cpudir = NULL;
+ g_autoptr(virDir) cpudir = NULL;
struct dirent *cpudirent = NULL;
g_autoptr(virBitmap) sockets_map = virBitmapNew(0);
virBitmap **cores_maps = NULL;
@@ -614,7 +614,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
{
g_autoptr(virBitmap) present_cpus_map = NULL;
g_autoptr(virBitmap) online_cpus_map = NULL;
- g_autoptr(DIR) nodedir = NULL;
+ g_autoptr(virDir) nodedir = NULL;
struct dirent *nodedirent = NULL;
int nodecpus, nodecores, nodesockets, nodethreads, offline = 0;
int threads_per_subcore = 0;
@@ -1686,7 +1686,7 @@ virHostCPUGetHaltPollTime(pid_t pid,
g_autofree char *debugFsPath = NULL;
g_autofree char *kvmPath = NULL;
struct dirent *ent = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
bool found = false;
if (!(debugFsPath = virFileFindMountPoint("debugfs")))
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 41d4cef8b9..77c385f6fb 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -527,7 +527,7 @@ int
virMediatedDeviceParentGetAddress(const char *sysfspath,
char **address)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
if (virDirOpen(&dir, MDEV_BUS_DIR) < 0)
return -1;
@@ -557,7 +557,7 @@ virMediatedDeviceGetMdevTypes(const char *sysfspath,
{
ssize_t ret = -1;
int dirret = -1;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
g_autofree char *types_path = NULL;
g_autoptr(virMediatedDeviceType) mdev_type = NULL;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 62d8162e03..84582a0c52 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -2971,7 +2971,7 @@ virNetDevRDMAFeature(const char *ifname,
{
g_autofree char *eth_devpath = NULL;
g_autofree char *eth_res_buf = NULL;
- g_autoptr(DIR) dirp = NULL;
+ g_autoptr(virDir) dirp = NULL;
struct dirent *dp;
if (!virFileExists(SYSFS_INFINIBAND_DIR))
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index 43e299f4bb..a16a454cdb 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -762,7 +762,7 @@ virNumaGetPages(int node,
unsigned long long **pages_free,
size_t *npages)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int direrr = 0;
struct dirent *entry;
unsigned int ntmp = 0;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 7800966963..668821e433 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -461,7 +461,7 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate,
virPCIDevice **matched,
void *data)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
int ret = 0;
int rc;
@@ -1805,7 +1805,7 @@ int virPCIDeviceFileIterate(virPCIDevice *dev,
void *opaque)
{
g_autofree char *pcidir = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *ent;
int direrr;
@@ -1851,7 +1851,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddress *orig,
void *opaque)
{
g_autofree char *groupPath = NULL;
- g_autoptr(DIR) groupDir = NULL;
+ g_autoptr(virDir) groupDir = NULL;
struct dirent *ent;
int direrr;
@@ -2495,7 +2495,7 @@ virPCIGetNetName(const char *device_link_sysfs_path,
g_autofree char *physPortID = NULL;
g_autofree char *pcidev_sysfs_net_path = NULL;
g_autofree char *firstEntryName = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry = NULL;
size_t i = 0;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 39ca5de811..85a16f98e4 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -612,7 +612,7 @@ virProcessGetAffinity(pid_t pid G_GNUC_UNUSED)
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
{
int ret = -1;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int value;
struct dirent *ent;
g_autofree char *taskPath = NULL;
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index c46a78f113..451f32d6a9 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -517,7 +517,7 @@ virResctrlUnlock(int fd G_GNUC_UNUSED)
/* virResctrlInfo-related definitions */
static int
virResctrlGetCacheInfo(virResctrlInfo *resctrl,
- DIR *dirp)
+ virDir *dirp)
{
int rv = -1;
struct dirent *ent = NULL;
@@ -752,7 +752,7 @@ virResctrlGetMonitorInfo(virResctrlInfo *resctrl)
static int
virResctrlGetInfo(virResctrlInfo *resctrl)
{
- g_autoptr(DIR) dirp = NULL;
+ g_autoptr(virDir) dirp = NULL;
int ret = -1;
ret = virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info");
@@ -1832,7 +1832,7 @@ virResctrlAllocGetUnused(virResctrlInfo *resctrl)
g_autoptr(virResctrlAlloc) ret = NULL;
g_autoptr(virResctrlAlloc) alloc_default = NULL;
struct dirent *ent = NULL;
- g_autoptr(DIR) dirp = NULL;
+ g_autoptr(virDir) dirp = NULL;
int rv = -1;
if (virResctrlInfoIsEmpty(resctrl)) {
@@ -2569,7 +2569,7 @@ virResctrlMonitorGetStats(virResctrlMonitor *monitor,
int ret = -1;
size_t i = 0;
unsigned long long val = 0;
- g_autoptr(DIR) dirp = NULL;
+ g_autoptr(virDir) dirp = NULL;
g_autofree char *datapath = NULL;
struct dirent *ent = NULL;
virResctrlMonitorStats *stat = NULL;
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index 6a90d9002f..10324f05d6 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -104,7 +104,7 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
unsigned int target,
unsigned long long unit)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
unsigned int adapter_id;
@@ -136,7 +136,7 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
unsigned int target,
unsigned long long unit)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
unsigned int adapter_id;
diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c
index 969cdd9f79..ba7acce5dc 100644
--- a/src/util/virscsihost.c
+++ b/src/util/virscsihost.c
@@ -94,7 +94,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix,
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH;
struct dirent *entry = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
char *host_link = NULL;
char *host_path = NULL;
char *p = NULL;
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 9e6ec9c9cf..56aa48b652 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -110,7 +110,7 @@ virUSBDeviceSearch(unsigned int vendor,
const char *vroot,
unsigned int flags)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
bool found = false;
char *ignore = NULL;
struct dirent *de;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 7e246d22d1..095c703d6a 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1430,7 +1430,7 @@ virMemoryMaxValue(bool capped)
bool
virHostHasIOMMU(void)
{
- g_autoptr(DIR) iommuDir = NULL;
+ g_autoptr(virDir) iommuDir = NULL;
struct dirent *iommuGroup = NULL;
int direrr;
@@ -1461,7 +1461,7 @@ virHostHasIOMMU(void)
char *
virHostGetDRMRenderNode(void)
{
- g_autoptr(DIR) driDir = NULL;
+ g_autoptr(virDir) driDir = NULL;
const char *driPath = "/dev/dri";
struct dirent *ent = NULL;
int dirErr = 0;
diff --git a/src/util/virvhba.c b/src/util/virvhba.c
index 5ceedc8076..968653a5d8 100644
--- a/src/util/virvhba.c
+++ b/src/util/virvhba.c
@@ -153,7 +153,7 @@ char *
virVHBAFindVportHost(const char *sysfs_prefix)
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *entry = NULL;
if (virDirOpen(&dir, prefix) < 0)
@@ -342,7 +342,7 @@ virVHBAGetHostByWWN(const char *sysfs_prefix,
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
struct dirent *entry = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
if (virDirOpen(&dir, prefix) < 0)
return NULL;
@@ -384,7 +384,7 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix,
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
struct dirent *entry = NULL;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
if (virDirOpen(&dir, prefix) < 0)
return NULL;
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 6d3decdc16..7648ead735 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -727,7 +727,7 @@ testQemuGetLatestCapsForArch(const char *arch,
const char *suffix)
{
struct dirent *ent;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int rc;
g_autofree char *fullsuffix = NULL;
unsigned long maxver = 0;
@@ -811,7 +811,7 @@ testQemuCapsIterate(const char *suffix,
void *opaque)
{
struct dirent *ent;
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
int rc;
bool fail = false;
diff --git a/tests/virschematest.c b/tests/virschematest.c
index fcf3838630..19720c3021 100644
--- a/tests/virschematest.c
+++ b/tests/virschematest.c
@@ -84,7 +84,7 @@ testSchemaDir(const char *schema,
const char *dir_path,
const char *filterstr)
{
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
struct dirent *ent;
int ret = 0;
int rc;
diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c
index 2ac96d1e19..a1fb64ada2 100644
--- a/tools/virt-host-validate-common.c
+++ b/tools/virt-host-validate-common.c
@@ -372,7 +372,7 @@ int virHostValidateIOMMU(const char *hvname,
} else if (ARCH_IS_PPC64(arch)) {
virHostMsgPass();
} else if (ARCH_IS_S390(arch)) {
- g_autoptr(DIR) dir = NULL;
+ g_autoptr(virDir) dir = NULL;
/* On s390x, we skip the IOMMU check if there are no PCI
* devices (which is quite usual on s390x). If there are
--
2.38.2