Introduce VIR_CLOSE to be used rather than close()

Since bugs due to double-closed file descriptors are difficult to track down in a multi-threaded system, I am introducing the VIR_CLOSE(fd) macro to help avoid mistakes here.

There are lots of places where close() is being used. In this patch I am only cleaning up usage of close() in src/conf where the problems were.

I also dare to declare close() as being deprecated in libvirt code base (HACKING).
This commit is contained in:
Stefan Berger
2010-10-19 10:23:51 -04:00
parent b2c9a87940
commit f04de501bc
11 changed files with 161 additions and 22 deletions
+17
View File
@@ -318,6 +318,23 @@ routines, use the macros from memory.h
VIR_FREE(domain);
File handling
=============
Use of the close() API is deprecated in libvirt code base to help avoiding
double-closing of a file descriptor. Instead of this API, use the macro from
files.h
- eg close a file descriptor
if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("failed to close file"));
}
- eg close a file descriptor in an error path, without losing the previous
errno value
VIR_FORCE_CLOSE(fd);
String comparisons
==================