mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
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:
@@ -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) < 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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user