$(_sc_search_regexp)
sc_prohibit_readdir:
- @prohibit='\breaddir *\(' \
+ @prohibit='\b(read|close)dir *\(' \
exclude='exempt from syntax-check' \
- halt='use virDirRead, not readdir' \
+ halt='use virDirRead and VIR_DIR_CLOSE' \
$(_sc_search_regexp)
sc_prohibit_gettext_noop:
virNetworkObjEndAPI(&net);
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}
virNetworkObjEndAPI(&net);
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}
virNWFilterObjUnlock(nwfilter);
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}
virStoragePoolObjUnlock(pool);
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}
VIR_FREE(autostartLink);
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}
}
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
virObjectUnlock(doms);
return ret;
}
virSecretObjEndAPI(&secret);
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return 0;
}
safewrite;
safezero;
virBuildPathInternal;
+virDirClose;
virDirCreate;
virDirRead;
virFileAbsPath;
ret = 0;
cleanup:
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(oldPath);
VIR_FREE(newPath);
VIR_FREE(contents);
openvzSetUUID(vpsid);
}
- closedir(dp);
+ VIR_DIR_CLOSE(dp);
VIR_FREE(conf_dir);
return ret;
}
ret = 0;
cleanup:
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(snapDir);
virObjectUnref(caps);
virObjectUnlock(vm);
ret = true;
cleanup:
- if (iommuDir)
- closedir(iommuDir);
-
+ VIR_DIR_CLOSE(iommuDir);
return ret;
}
if (virAsprintf(&stablepath, "%s/%s",
pool->def->target.path,
dent->d_name) == -1) {
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return NULL;
}
if (virFileLinkPointsTo(stablepath, devpath)) {
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return stablepath;
}
goto retry;
}
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
ret_strdup:
/* Couldn't find any matching stable link so give back
}
if (direrr < 0)
goto cleanup;
- closedir(dir);
- dir = NULL;
+ VIR_DIR_CLOSE(dir);
vol = NULL;
if (VIR_ALLOC(target))
ret = 0;
cleanup:
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FORCE_CLOSE(fd);
virStorageVolDefFree(vol);
virStorageSourceFree(target);
if (direrr < 0)
retval = -1;
- closedir(sysdir);
+ VIR_DIR_CLOSE(sysdir);
out:
return retval;
}
retval = 0;
cleanup:
- if (block_dir)
- closedir(block_dir);
+ VIR_DIR_CLOSE(block_dir);
VIR_FREE(block_path);
return retval;
}
retval = 0;
cleanup:
- if (lun_dir)
- closedir(lun_dir);
+ VIR_DIR_CLOSE(lun_dir);
VIR_FREE(lun_path);
return retval;
}
found++;
}
- closedir(devicedir);
+ VIR_DIR_CLOSE(devicedir);
if (retval < 0)
return -1;
VIR_ERROR(_("Failed to readdir for %s (%d)"), grppath, errno);
}
- closedir(grpdir);
+ VIR_DIR_CLOSE(grpdir);
VIR_DEBUG("Removing cgroup %s", grppath);
if (rmdir(grppath) != 0 && errno != ENOENT) {
cleanup:
virCgroupFree(&subgroup);
VIR_FREE(keypath);
- if (dp)
- closedir(dp);
-
+ VIR_DIR_CLOSE(dp);
return ret;
}
}
VIR_FREE(base);
- closedir(dh);
- dh = NULL;
+ VIR_DIR_CLOSE(dh);
}
ret = 0;
cleanup:
- if (dh)
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
VIR_FREE(entry);
VIR_FREE(base);
return ret;
VIR_DEBUG("No free loop devices available");
VIR_FREE(looppath);
}
- if (dh)
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return fd;
}
_("No free NBD devices"));
cleanup:
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return ret;
}
cleanup:
VIR_FREE(filepath);
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return ret;
}
return !!*ent;
}
+void virDirClose(DIR **dirp)
+{
+ if (!*dirp)
+ return;
+
+ closedir(*dirp); /* exempt from syntax-check */
+ *dirp = NULL;
+}
+
static int
virFileMakePathHelper(char *path, mode_t mode)
{
unsigned int flags) ATTRIBUTE_RETURN_CHECK;
int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+void virDirClose(DIR **dirp)
+ ATTRIBUTE_NONNULL(1);
+# define VIR_DIR_CLOSE(dir) virDirClose(&(dir))
int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
int virFileMakePathWithMode(const char *path,
ret = processors;
cleanup:
- if (cpudir)
- closedir(cpudir);
+ VIR_DIR_CLOSE(cpudir);
if (cores_maps)
for (i = 0; i < sock_max; i++)
virBitmapFree(cores_maps[i]);
ret = 0;
cleanup:
- if (nodedir)
- closedir(nodedir);
+ VIR_DIR_CLOSE(nodedir);
virBitmapFree(present_cpus_map);
virBitmapFree(online_cpus_map);
VIR_FREE(sysfs_nodedir);
ret = 0;
cleanup:
- closedir(dirp);
+ VIR_DIR_CLOSE(dirp);
VIR_FREE(eth_devpath);
VIR_FREE(ib_devpath);
VIR_FREE(eth_res_buf);
cleanup:
VIR_FREE(devpath);
VIR_FORCE_CLOSE(fd);
- closedir(dirp);
+ VIR_DIR_CLOSE(dirp);
return ret;
#else
return NULL;
VIR_FREE(tmp_free);
VIR_FREE(tmp_avail);
VIR_FREE(tmp_size);
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(path);
return ret;
}
virPCIDeviceFree(check);
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}
ret = 0;
cleanup:
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(file);
VIR_FREE(pcidir);
return ret;
cleanup:
VIR_FREE(groupPath);
- if (groupDir)
- closedir(groupDir);
+ VIR_DIR_CLOSE(groupDir);
return ret;
}
break;
}
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
out:
VIR_FREE(pcidev_sysfs_net_path);
ret = 0;
cleanup:
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(taskPath);
if (ret < 0)
VIR_FREE(*pids);
}
cleanup:
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(path);
return sg;
}
}
cleanup:
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(path);
return name;
}
ret = list;
cleanup:
- if (dir)
- closedir(dir);
-
+ VIR_DIR_CLOSE(dir);
if (!ret)
virObjectUnref(list);
return ret;
}
cleanup:
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(unique_path);
VIR_FREE(host_link);
VIR_FREE(host_path);
cleanup:
# undef READ_WWN
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(wwnn_path);
VIR_FREE(wwpn_path);
VIR_FREE(wwnn_buf);
}
cleanup:
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
VIR_FREE(max_vports);
VIR_FREE(vports);
return ret;
/* Build the full file path */
if (!(path = virFileBuildPath(priv->configDir, ent->d_name, NULL))) {
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return -1;
}
if (xenInotifyAddDomainConfigInfo(conn, path, now) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Error adding file to config list"));
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
VIR_FREE(path);
return -1;
}
VIR_FREE(path);
}
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
if (direrr < 0)
return -1;
}
/* Build the full file path */
if (!(path = virFileBuildPath(priv->configDir, ent->d_name, NULL))) {
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return -1;
}
args.priv = priv;
virHashRemoveSet(priv->configCache, xenXMConfigReaper, &args);
- closedir(dh);
+ VIR_DIR_CLOSE(dh);
return ret;
}
cleanup:
VIR_FREE(test_name);
VIR_FREE(xml_path);
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}
VIR_FREE(path);
}
- closedir(dir);
- dir = NULL;
+ VIR_DIR_CLOSE(dir);
nleases = virJSONValueArraySize(leases_array);
DEBUG("Read %zd leases", nleases);
*errnop = errno;
VIR_FREE(tmpAddress);
virJSONValueFree(leases_array);
- if (dir)
- closedir(dir);
+ VIR_DIR_CLOSE(dir);
return ret;
}