Switch from opendir to virDirOpen everywhere we need to report an error.
int direrr;
int fd = -1, ret = -1;
- if (!(dir = opendir(pool->def->target.path))) {
- virReportSystemError(errno,
- _("cannot open path '%s'"),
- pool->def->target.path);
+ if (virDirOpen(&dir, pool->def->target.path) < 0)
goto cleanup;
- }
while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) {
int err;
virFileWaitForDevices();
- sysdir = opendir(sysfs_path);
-
- if (sysdir == NULL) {
+ if (virDirOpen(&sysdir, sysfs_path) < 0)
virReportSystemError(errno,
_("Failed to opendir path '%s'"), sysfs_path);
retval = -1;
VIR_DEBUG("Looking for block device in '%s'", block_path);
- if (!(block_dir = opendir(block_path))) {
- virReportSystemError(errno,
- _("Failed to opendir sysfs path '%s'"),
- block_path);
+ if (virDirOpen(&block_dir, block_path) < 0)
goto cleanup;
- }
while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0)
host, bus, target, lun) < 0)
goto cleanup;
- if (!(lun_dir = opendir(lun_path))) {
- virReportSystemError(errno,
- _("Failed to opendir sysfs path '%s'"),
- lun_path);
+ if (virDirOpen(&lun_dir, lun_path) < 0)
goto cleanup;
- }
while ((direrr = virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) {
if (STREQLEN(lun_dirent->d_name, "block", 5)) {
virFileWaitForDevices();
- devicedir = opendir(device_path);
-
- if (devicedir == NULL) {
- virReportSystemError(errno,
- _("Failed to opendir path '%s'"), device_path);
+ if (virDirOpen(&devicedir, device_path) < 0)
return -1;
- }
snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
cgroup->controllers[i].placement) < 0)
goto cleanup;
- if (!(dh = opendir(base))) {
- virReportSystemError(errno,
- _("Unable to open dir '%s'"), base);
+ if (virDirOpen(&dh, base) < 0)
goto cleanup;
- }
while ((direrr = virDirRead(dh, &de, base)) > 0) {
if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)
VIR_DEBUG("Looking for loop devices in /dev");
- if (!(dh = opendir("/dev"))) {
- virReportSystemError(errno, "%s",
- _("Unable to read /dev"));
+ if (virDirOpen(&dh, "/dev") < 0)
goto cleanup;
- }
while ((direrr = virDirRead(dh, &de, "/dev")) > 0) {
/* Checking 'loop' prefix is insufficient, since
struct dirent *de;
int direrr;
- if (!(dh = opendir(SYSFS_BLOCK_DIR))) {
- virReportSystemError(errno,
- _("Cannot read directory %s"),
- SYSFS_BLOCK_DIR);
+ if (virDirOpen(&dh, SYSFS_BLOCK_DIR) < 0)
return NULL;
- }
while ((direrr = virDirRead(dh, &de, SYSFS_BLOCK_DIR)) > 0) {
if (STRPREFIX(de->d_name, "nbd")) {
if (!dir || !virFileExists(dir))
return 0;
- if (!(dh = opendir(dir))) {
- virReportSystemError(errno, _("Cannot open dir '%s'"),
- dir);
+ if (virDirOpen(&dh, dir) < 0)
return -1;
- }
while ((direrr = virDirRead(dh, &de, dir)) > 0) {
struct stat sb;
*cores = 0;
*sockets = 0;
- if (!(cpudir = opendir(node))) {
- virReportSystemError(errno, _("cannot opendir %s"), node);
+ if (virDirOpen(&cpudir, node) < 0)
goto cleanup;
- }
/* Keep track of the CPUs that belong to the current node */
if (!(node_cpus_map = virBitmapNew(npresent_cpus)))
if (!virFileExists(SYSFS_INFINIBAND_DIR))
return 0;
- if (!(dirp = opendir(SYSFS_INFINIBAND_DIR))) {
- virReportSystemError(errno,
- _("Failed to opendir path '%s'"),
- SYSFS_INFINIBAND_DIR);
+ if (virDirOpen(&dirp, SYSFS_INFINIBAND_DIR) < 0)
return -1;
- }
if (virAsprintf(ð_devpath, SYSFS_NET_DIR "%s/device/resource", ifname) < 0)
goto cleanup;
char *devpath = NULL;
int fd;
- DIR *dirp = opendir("/dev");
- if (dirp == NULL) {
- virReportSystemError(errno,
- _("Failed to opendir path '%s'"),
- "/dev");
+ if (virDirOpen(&dirp, "/dev") < 0)
return NULL;
- }
while (virDirRead(dirp, &dp, "/dev") > 0) {
if (STRPREFIX(dp->d_name, "tap")) {
VIR_DEBUG("%s %s: iterating over " PCI_SYSFS "devices", dev->id, dev->name);
- dir = opendir(PCI_SYSFS "devices");
- if (!dir) {
- VIR_WARN("Failed to open " PCI_SYSFS "devices");
+ if (virDirOpen(&dir, PCI_SYSFS "devices") < 0)
return -1;
- }
while ((ret = virDirRead(dir, &entry, PCI_SYSFS "devices")) > 0) {
unsigned int domain, bus, slot, function;
dev->address.slot, dev->address.function) < 0)
goto cleanup;
- if (!(dir = opendir(pcidir))) {
- virReportSystemError(errno,
- _("cannot open %s"), pcidir);
+ if (virDirOpen(&dir, pcidir) < 0)
goto cleanup;
- }
while ((direrr = virDirRead(dir, &ent, pcidir)) > 0) {
/* Device assignment requires:
(unsigned long long)pid) < 0)
goto cleanup;
- if (!(dir = opendir(taskPath)))
+ if (virDirOpen(&dir, taskPath) < 0)
goto cleanup;
while ((value = virDirRead(dir, &ent, taskPath)) > 0) {
prefix, adapter_id, bus, target, unit) < 0)
return NULL;
- if (!(dir = opendir(path))) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to open %s"), path);
+ if (virDirOpen(&dir, path) < 0)
goto cleanup;
- }
while (virDirRead(dir, &entry, path) > 0) {
/* Assume a single directory entry */
prefix, adapter_id, bus, target, unit) < 0)
return NULL;
- if (!(dir = opendir(path))) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to open %s"), path);
+ if (virDirOpen(&dir, path) < 0)
goto cleanup;
- }
while (virDirRead(dir, &entry, path) > 0) {
ignore_value(VIR_STRDUP(name, entry->d_name));
if (!(list = virUSBDeviceListNew()))
goto cleanup;
- dir = opendir(USB_SYSFS "/devices");
- if (!dir) {
- virReportSystemError(errno,
- _("Could not open directory %s"),
- USB_SYSFS "/devices");
+ if (virDirOpen(&dir, USB_SYSFS "/devices") < 0)
goto cleanup;
- }
while ((direrr = virDirRead(dir, &de, USB_SYSFS "/devices")) > 0) {
unsigned int found_prod, found_vend, found_bus, found_devno;
char *unique_path = NULL;
unsigned int read_unique_id;
- if (!(dir = opendir(prefix))) {
- virReportSystemError(errno,
- _("Failed to opendir path '%s'"),
- prefix);
+ if (virDirOpen(&dir, prefix) < 0)
return NULL;
- }
while (virDirRead(dir, &entry, prefix) > 0) {
if (!virFileIsLink(entry->d_name))
char *p;
char *ret = NULL;
- if (!(dir = opendir(prefix))) {
- virReportSystemError(errno,
- _("Failed to opendir path '%s'"),
- prefix);
+ if (virDirOpen(&dir, prefix) < 0)
return NULL;
- }
# define READ_WWN(wwn_path, buf) \
do { \
char *state = NULL;
char *ret = NULL;
- if (!(dir = opendir(prefix))) {
- virReportSystemError(errno,
- _("Failed to opendir path '%s'"),
- prefix);
+ if (virDirOpen(&dir, prefix) < 0)
return NULL;
- }
while (virDirRead(dir, &entry, prefix) > 0) {
unsigned int host;
return -1;
/* populate initial list */
- if (!(dh = opendir(priv->configDir))) {
- virReportSystemError(errno,
- _("cannot open directory: %s"),
- priv->configDir);
+ if (virDirOpen(&dh, priv->configDir) < 0)
return -1;
- }
+
while ((direrr = virDirRead(dh, &ent, priv->configDir)) > 0) {
if (STRPREFIX(ent->d_name, "."))
continue;
priv->lastRefresh = now;
/* Process the files in the config dir */
- if (!(dh = opendir(priv->configDir))) {
- virReportSystemError(errno,
- _("cannot read directory %s"),
- priv->configDir);
+ if (virDirOpen(&dh, priv->configDir) < 0)
return -1;
- }
while ((ret = virDirRead(dh, &ent, priv->configDir)) > 0) {
struct stat st;
.validator = validator,
};
- if (!(dir = opendir(dir_path))) {
- virReportSystemError(errno,
- "Failed to opendir path '%s'",
- dir_path);
+ if (virDirOpen(&dir, dir_path) < 0)
return -1;
- }
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
if (!virFileHasSuffix(ent->d_name, ".xml"))