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
+23
View File
@@ -389,7 +389,30 @@
</pre></li>
</ul>
<h2><a name="file_handling">File handling</a></h2>
<p>
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
</p>
<ul>
<li><p>eg close a file descriptor</p>
<pre>
if (VIR_CLOSE(fd) &lt; 0) {
virReportSystemError(errno, _("failed to close file"));
}
</pre></li>
<li><p>eg close a file descriptor in an error path, without losing
the previous errno value</p>
<pre>
VIR_FORCE_CLOSE(fd);
</pre></li>
</ul>
<h2><a name="string_comparision">String comparisons</a></h2>