[libvirt PATCH 0/6] Clean up some includes

Ján Tomko (6): util: virstring.h: remove stdarg.h include hyperv: include virxml.h util: viruri: move libxml include util: log: move virLogMessage util: virlog: unexport virLogVMessage tools: remove unnecessary includes src/hyperv/hyperv_wmi.c | 1 + src/libvirt_private.syms | 1 - src/util/virlog.c | 66 +++++++++++++++++---------------- src/util/virlog.h | 9 ----- src/util/virstring.h | 2 - src/util/viruri.c | 2 + src/util/viruri.h | 2 - tools/virsh-domain-monitor.c | 2 - tools/virsh-domain.c | 4 -- tools/virsh-host.c | 5 +-- tools/virsh-host.h | 2 +- tools/virsh-interface.c | 4 -- tools/virsh-network.c | 2 - tools/virsh-nodedev.c | 1 - tools/virsh-nwfilter.c | 1 - tools/virsh-secret.c | 1 - tools/virsh-secret.h | 2 +- tools/virsh-snapshot.c | 2 - tools/virsh-snapshot.h | 2 +- tools/virsh-volume.c | 2 - tools/virsh.h | 2 - tools/virt-admin-completer.c | 1 - tools/virt-admin.c | 4 +- tools/virt-host-validate-qemu.c | 1 - tools/vsh-table.c | 2 - tools/vsh.c | 3 -- tools/vsh.h | 2 - 27 files changed, 44 insertions(+), 84 deletions(-) -- 2.26.2

It was needed for virAsprintf, which is now dropped. Signed-off-by: Ján Tomko <jtomko@redhat.com> Fixes: 33ed622106c61d257fd4a5750d4df511bcdd1b2b --- src/util/virstring.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/virstring.h b/src/util/virstring.h index 360c68395c..c812157287 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -18,8 +18,6 @@ #pragma once -#include <stdarg.h> - #include "internal.h" #define VIR_INT64_STR_BUFLEN 21 -- 2.26.2

This file is using XML functions without including the header. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/hyperv/hyperv_wmi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index f8d0aaf373..917298d027 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -37,6 +37,7 @@ #include "virstring.h" #include "openwsman.h" #include "virlog.h" +#include "virxml.h" #define WS_SERIALIZER_FREE_MEM_WORKS 0 -- 2.26.2

The XML function is needed in the C file, not in the header. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/viruri.c | 2 ++ src/util/viruri.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/viruri.c b/src/util/viruri.c index 492454a3df..598adffede 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -20,6 +20,8 @@ #include <config.h> +#include <libxml/uri.h> + #include "viruri.h" #include "viralloc.h" diff --git a/src/util/viruri.h b/src/util/viruri.h index 1735620a2f..e607ecc109 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -20,8 +20,6 @@ #pragma once -#include <libxml/uri.h> - #include "internal.h" #include "virconf.h" -- 2.26.2

This function calls virLogVMessage. Move it below the definition of virLogVMessage so it can call it even without a prototype. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/util/virlog.c | 63 ++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index dabfe7e501..983c2565ad 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -478,37 +478,6 @@ virLogSourceUpdate(virLogSourcePtr source) virLogUnlock(); } -/** - * virLogMessage: - * @source: where is that message coming from - * @priority: the priority level - * @filename: file where the message was emitted - * @linenr: line where the message was emitted - * @funcname: the function emitting the (debug) message - * @metadata: NULL or metadata array, terminated by an item with NULL key - * @fmt: the string format - * @...: the arguments - * - * Call the libvirt logger with some information. Based on the configuration - * the message may be stored, sent to output or just discarded - */ -void -virLogMessage(virLogSourcePtr source, - virLogPriority priority, - const char *filename, - int linenr, - const char *funcname, - virLogMetadataPtr metadata, - const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - virLogVMessage(source, priority, - filename, linenr, funcname, - metadata, fmt, ap); - va_end(ap); -} - /** * virLogVMessage: @@ -639,6 +608,38 @@ virLogVMessage(virLogSourcePtr source, } +/** + * virLogMessage: + * @source: where is that message coming from + * @priority: the priority level + * @filename: file where the message was emitted + * @linenr: line where the message was emitted + * @funcname: the function emitting the (debug) message + * @metadata: NULL or metadata array, terminated by an item with NULL key + * @fmt: the string format + * @...: the arguments + * + * Call the libvirt logger with some information. Based on the configuration + * the message may be stored, sent to output or just discarded + */ +void +virLogMessage(virLogSourcePtr source, + virLogPriority priority, + const char *filename, + int linenr, + const char *funcname, + virLogMetadataPtr metadata, + const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + virLogVMessage(source, priority, + filename, linenr, funcname, + metadata, fmt, ap); + va_end(ap); +} + + static void virLogOutputToFd(virLogSourcePtr source G_GNUC_UNUSED, virLogPriority priority G_GNUC_UNUSED, -- 2.26.2

Last usage out of virlog.c was removed by commit 91268c715cf0293f0751de0450e4d0c06bea18d8 node_device_udev: remove deprecated logging function Also drop the virbuffer.h include - it seems it was never used for anything else than the transitive stdarg.h include. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/libvirt_private.syms | 1 - src/util/virlog.c | 3 ++- src/util/virlog.h | 9 --------- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index eea31a736d..1fae05057e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2474,7 +2474,6 @@ virLogSetFilters; virLogSetFromEnv; virLogSetOutputs; virLogUnlock; -virLogVMessage; # util/virmacaddr.h diff --git a/src/util/virlog.c b/src/util/virlog.c index 983c2565ad..322f9599f6 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -493,7 +493,8 @@ virLogSourceUpdate(virLogSourcePtr source) * Call the libvirt logger with some information. Based on the configuration * the message may be stored, sent to output or just discarded */ -void +static void +G_GNUC_PRINTF(7, 0) virLogVMessage(virLogSourcePtr source, virLogPriority priority, const char *filename, diff --git a/src/util/virlog.h b/src/util/virlog.h index feb2f85904..9913a194fd 100644 --- a/src/util/virlog.h +++ b/src/util/virlog.h @@ -22,7 +22,6 @@ #pragma once #include "internal.h" -#include "virbuffer.h" #ifdef PACKAGER_VERSION # ifdef PACKAGER @@ -199,14 +198,6 @@ void virLogMessage(virLogSourcePtr source, const char *funcname, virLogMetadataPtr metadata, const char *fmt, ...) G_GNUC_PRINTF(7, 8); -void virLogVMessage(virLogSourcePtr source, - virLogPriority priority, - const char *filename, - int linenr, - const char *funcname, - virLogMetadataPtr metadata, - const char *fmt, - va_list vargs) G_GNUC_PRINTF(7, 0); bool virLogProbablyLogMessage(const char *str); virLogOutputPtr virLogOutputNew(virLogOutputFunc f, -- 2.26.2

After the split of virsh to multiple files, and the subsequent split to vsh/virt-admin, there are quite a few leftovers. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain-monitor.c | 2 -- tools/virsh-domain.c | 4 ---- tools/virsh-host.c | 5 +---- tools/virsh-host.h | 2 +- tools/virsh-interface.c | 4 ---- tools/virsh-network.c | 2 -- tools/virsh-nodedev.c | 1 - tools/virsh-nwfilter.c | 1 - tools/virsh-secret.c | 1 - tools/virsh-secret.h | 2 +- tools/virsh-snapshot.c | 2 -- tools/virsh-snapshot.h | 2 +- tools/virsh-volume.c | 2 -- tools/virsh.h | 2 -- tools/virt-admin-completer.c | 1 - tools/virt-admin.c | 4 +++- tools/virt-host-validate-qemu.c | 1 - tools/vsh-table.c | 2 -- tools/vsh.c | 3 --- tools/vsh.h | 2 -- 20 files changed, 7 insertions(+), 38 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index d8333a2f44..0111116885 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -23,9 +23,7 @@ #include "virsh-util.h" #include <libxml/parser.h> -#include <libxml/tree.h> #include <libxml/xpath.h> -#include <libxml/xmlsave.h> #include "internal.h" #include "conf/virdomainobjlist.h" diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index aaf3b9a6a5..86dfdd3fbc 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -24,12 +24,9 @@ #include <fcntl.h> #include <signal.h> -#include <sys/time.h> #include <libxml/parser.h> -#include <libxml/tree.h> #include <libxml/xpath.h> -#include <libxml/xmlsave.h> #include "internal.h" #include "virbitmap.h" @@ -50,7 +47,6 @@ #include "virtime.h" #include "virtypedparam.h" #include "virxml.h" -#include "virsh-nodedev.h" #include "viruri.h" #include "vsh-table.h" #include "virenum.h" diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 0fd77cbae5..dab0b92229 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -20,18 +20,15 @@ #include <config.h> #include "virsh-host.h" +#include "virsh.h" #include <libxml/parser.h> -#include <libxml/tree.h> #include <libxml/xpath.h> -#include <libxml/xmlsave.h> #include "internal.h" #include "virbitmap.h" -#include "virbuffer.h" #include "viralloc.h" #include "virxml.h" -#include "virtypedparam.h" #include "virstring.h" #include "virfile.h" #include "virenum.h" diff --git a/tools/virsh-host.h b/tools/virsh-host.h index f4c2aa316d..92328c7deb 100644 --- a/tools/virsh-host.h +++ b/tools/virsh-host.h @@ -20,6 +20,6 @@ #pragma once -#include "virsh.h" +#include "vsh.h" extern const vshCmdDef hostAndHypervisorCmds[]; diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index d754998d52..b8e424091d 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -31,17 +31,13 @@ #include "virsh-interface.h" #include <libxml/parser.h> -#include <libxml/tree.h> #include <libxml/xpath.h> -#include <libxml/xmlsave.h> #include "internal.h" -#include "virbuffer.h" #include "viralloc.h" #include "virfile.h" #include "virmacaddr.h" #include "virxml.h" -#include "virstring.h" #include "vsh-table.h" virInterfacePtr diff --git a/tools/virsh-network.c b/tools/virsh-network.c index ed90736345..6cf40a8ad2 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -22,10 +22,8 @@ #include "virsh-network.h" #include "internal.h" -#include "virbuffer.h" #include "viralloc.h" #include "virfile.h" -#include "virstring.h" #include "virtime.h" #include "conf/network_conf.h" #include "vsh-table.h" diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 7f091d7cf8..ff028d377e 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -22,7 +22,6 @@ #include "virsh-nodedev.h" #include "internal.h" -#include "virbuffer.h" #include "viralloc.h" #include "virfile.h" #include "virstring.h" diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 6e5213dea3..38790b0081 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -22,7 +22,6 @@ #include "virsh-nwfilter.h" #include "internal.h" -#include "virbuffer.h" #include "viralloc.h" #include "virfile.h" #include "vsh-table.h" diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 7bd0acda58..7f1df30090 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -28,7 +28,6 @@ #include "virfile.h" #include "virutil.h" #include "virsecret.h" -#include "virstring.h" #include "virtime.h" #include "vsh-table.h" #include "virenum.h" diff --git a/tools/virsh-secret.h b/tools/virsh-secret.h index 6ebe573f87..eea542c0ef 100644 --- a/tools/virsh-secret.h +++ b/tools/virsh-secret.h @@ -20,7 +20,7 @@ #pragma once -#include "virsh.h" +#include "vsh.h" struct virshSecretEventCallback { const char *name; diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 4ac6cb1dcd..e3599a3535 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -24,9 +24,7 @@ #include <assert.h> #include <libxml/parser.h> -#include <libxml/tree.h> #include <libxml/xpath.h> -#include <libxml/xmlsave.h> #include "internal.h" #include "virbuffer.h" diff --git a/tools/virsh-snapshot.h b/tools/virsh-snapshot.h index 49517a4235..66ebc07175 100644 --- a/tools/virsh-snapshot.h +++ b/tools/virsh-snapshot.h @@ -20,6 +20,6 @@ #pragma once -#include "virsh.h" +#include "vsh.h" extern const vshCmdDef snapshotCmds[]; diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index fec8278a5d..e04e2db096 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -25,9 +25,7 @@ #include <fcntl.h> #include <libxml/parser.h> -#include <libxml/tree.h> #include <libxml/xpath.h> -#include <libxml/xmlsave.h> #include "internal.h" #include "virbuffer.h" diff --git a/tools/virsh.h b/tools/virsh.h index ef18c7f421..1b896cd535 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -20,9 +20,7 @@ #pragma once -#include <stdarg.h> #include <unistd.h> -#include <sys/stat.h> #include "internal.h" #include "virerror.h" diff --git a/tools/virt-admin-completer.c b/tools/virt-admin-completer.c index 25dacf51d8..7201bb71eb 100644 --- a/tools/virt-admin-completer.c +++ b/tools/virt-admin-completer.c @@ -24,7 +24,6 @@ #include "internal.h" #include "virt-admin.h" #include "viralloc.h" -#include "virstring.h" char ** diff --git a/tools/virt-admin.c b/tools/virt-admin.c index fef0332a0d..c3ec110bf9 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -19,8 +19,9 @@ */ #include <config.h> -#include "virt-admin.h" +#include <stdio.h> +#include <unistd.h> #include <getopt.h> #if WITH_READLINE @@ -29,6 +30,7 @@ #endif #include "internal.h" +#include "virt-admin.h" #include "viralloc.h" #include "virerror.h" #include "virfile.h" diff --git a/tools/virt-host-validate-qemu.c b/tools/virt-host-validate-qemu.c index ea7f172790..f9432f522d 100644 --- a/tools/virt-host-validate-qemu.c +++ b/tools/virt-host-validate-qemu.c @@ -20,7 +20,6 @@ */ #include <config.h> -#include <unistd.h> #include "virt-host-validate-qemu.h" #include "virt-host-validate-common.h" diff --git a/tools/vsh-table.c b/tools/vsh-table.c index 60554b7b2f..a727ac17b5 100644 --- a/tools/vsh-table.c +++ b/tools/vsh-table.c @@ -28,8 +28,6 @@ #include "viralloc.h" #include "virbuffer.h" -#include "virstring.h" -#include "virsh-util.h" #define HEX_ENCODE_LENGTH 4 /* represents length of '\xNN' */ diff --git a/tools/vsh.c b/tools/vsh.c index b65e99cbd2..6dfa9fe61d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -24,9 +24,7 @@ #include <assert.h> #include <stdarg.h> #include <unistd.h> -#include <sys/time.h> #include <fcntl.h> -#include <time.h> #include <sys/stat.h> #include <inttypes.h> #include <signal.h> @@ -42,7 +40,6 @@ #include "virfile.h" #include "virthread.h" #include "vircommand.h" -#include "virtypedparam.h" #include "virstring.h" #include "virutil.h" diff --git a/tools/vsh.h b/tools/vsh.h index 174116b369..290bb71f3e 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -21,8 +21,6 @@ #pragma once #include <stdarg.h> -#include <unistd.h> -#include <sys/stat.h> #ifndef WIN32 # include <termios.h> #endif -- 2.26.2

On Mon, Aug 03, 2020 at 12:24:18AM +0200, Ján Tomko wrote:
Ján Tomko (6): util: virstring.h: remove stdarg.h include hyperv: include virxml.h util: viruri: move libxml include util: log: move virLogMessage util: virlog: unexport virLogVMessage tools: remove unnecessary includes
This will always be an issue in such C code unless we use something that includes all includes (or at least a group of them). We'd have `util.h` for everything from `src/util/`, `conf.h` for everything from `src/conf/` and few others. Until then there will be leftovers. Anyway, Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/hyperv/hyperv_wmi.c | 1 + src/libvirt_private.syms | 1 - src/util/virlog.c | 66 +++++++++++++++++---------------- src/util/virlog.h | 9 ----- src/util/virstring.h | 2 - src/util/viruri.c | 2 + src/util/viruri.h | 2 - tools/virsh-domain-monitor.c | 2 - tools/virsh-domain.c | 4 -- tools/virsh-host.c | 5 +-- tools/virsh-host.h | 2 +- tools/virsh-interface.c | 4 -- tools/virsh-network.c | 2 - tools/virsh-nodedev.c | 1 - tools/virsh-nwfilter.c | 1 - tools/virsh-secret.c | 1 - tools/virsh-secret.h | 2 +- tools/virsh-snapshot.c | 2 - tools/virsh-snapshot.h | 2 +- tools/virsh-volume.c | 2 - tools/virsh.h | 2 - tools/virt-admin-completer.c | 1 - tools/virt-admin.c | 4 +- tools/virt-host-validate-qemu.c | 1 - tools/vsh-table.c | 2 - tools/vsh.c | 3 -- tools/vsh.h | 2 - 27 files changed, 44 insertions(+), 84 deletions(-)
-- 2.26.2
participants (2)
-
Ján Tomko
-
Martin Kletzander