* cfg.mk (sc_prohibit_close): New syntax-check rule. * src/util/pci.c (pciWaitForDeviceCleanup): Fix violation. * .x-sc_prohibit_close: New exceptions. * Makefile.am (EXTRA_DIST): Distribute new file. --- As promised, here's my followup to Stefan's recent close() cleanups, which will help us avoid further regressions. .x-sc_prohibit_close | 3 +++ Makefile.am | 1 + cfg.mk | 9 +++++++++ src/util/pci.c | 2 +- 4 files changed, 14 insertions(+), 1 deletions(-) create mode 100644 .x-sc_prohibit_close diff --git a/.x-sc_prohibit_close b/.x-sc_prohibit_close new file mode 100644 index 0000000..348200c --- /dev/null +++ b/.x-sc_prohibit_close @@ -0,0 +1,3 @@ +^docs/.* +^HACKING$ +^src/util/files.c$ diff --git a/Makefile.am b/Makefile.am index d3f8876..bf1b49b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,6 +26,7 @@ EXTRA_DIST = \ .x-sc_bindtextdomain \ .x-sc_m4_quote_check \ .x-sc_prohibit_asprintf \ + .x-sc_prohibit_close \ .x-sc_prohibit_empty_lines_at_EOF \ .x-sc_prohibit_gethostby \ .x-sc_prohibit_gethostname \ diff --git a/cfg.mk b/cfg.mk index 0851f44..963c7db 100644 --- a/cfg.mk +++ b/cfg.mk @@ -231,6 +231,15 @@ sc_avoid_write: halt='consider using safewrite instead of write' \ $(_sc_search_regexp) +# Avoid functions that can lead to double-close bugs. +sc_prohibit_close: + @prohibit='\<[f]close *\(' \ + halt='use VIR_{FORCE_}[F]CLOSE instead of [f]close' \ + $(_sc_search_regexp) + @prohibit='\<fdopen *\(' \ + halt='use VIR_FDOPEN instead of fdopen' \ + $(_sc_search_regexp) + # Similar to the gnulib maint.mk rule for sc_prohibit_strcmp # Use STREQLEN or STRPREFIX rather than comparing strncmp == 0, or != 0. sc_prohibit_strncmp: diff --git a/src/util/pci.c b/src/util/pci.c index bd8c6c5..d38cefa 100644 --- a/src/util/pci.c +++ b/src/util/pci.c @@ -1095,7 +1095,7 @@ pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher) } } - fclose(fp); + VIR_FORCE_FCLOSE(fp); return ret; } -- 1.7.3.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list