On Mon, Apr 06, 2026 at 23:29:17 -0400, Laine Stump via Devel wrote: > From: Laine Stump <[email protected]> > > The same several lines were repeated, once in a loop iterating through > all log targets, and again to output to stderr when there are no log > targets specified. This just moves those lines into a helper function, > making it easier and less error prone to add additional info the the > banner that is logged each time a daemon starts logging. > > Signed-off-by: Laine Stump <[email protected]> > --- > src/util/virlog.c | 127 ++++++++++++++++++++++++++++------------------ > 1 file changed, 79 insertions(+), 48 deletions(-) > > diff --git a/src/util/virlog.c b/src/util/virlog.c > index 30cb68fe7d..7a9b1e75d5 100644 > --- a/src/util/virlog.c > +++ b/src/util/virlog.c > @@ -479,6 +479,75 @@ virLogSourceUpdate(virLogSource *source) > } > > > +/** > + * virLogToOneTarget: > + * > + * (these first several args are coming directly from the args of > + * virLogVMessage() - you can find their description there) > + * > + * @source, @priority, @filename, @linenr, @funcname, @metadata: > + * > + * (the next 3 are created once during each call to virLogMMessage() and > reused > + * for each target) > + * > + * @timestamp: cached (during this one log to multiple targets) raw time > + * @str: the log message formatted from what appears in the VIR_*() > + or virReport*() call > + * @msg: the formatted log message with function name, line number, > and > + * priority added > + * > + * @outputFunc: pointer to function to call to output the data > + * @data: private data used by @outputFunc (e.g. fd to write to) > + * @needInit: pointer to bool that gets set to false once the > + * once-per-daemon-run init message has been sent to this > target > + * > + * If needInit is true, construct the strings to send the "init" > + * message (a banner with software version, etc) to the log target > + * using @outputFunc and set @needInit to false. Then send the current > + * log message to the target (described by the other args) using > + * @outputFunc. > + */ > +static void > +virLogToOneTarget(virLogSource *source, > + virLogPriority priority, > + const char *filename, > + int linenr, > + const char *funcname, > + virLogMetadata *metadata, > + const char *timestamp, > + const char *str, > + const char *msg, > + virLogOutputFunc outputFunc, > + void *data, > + bool *needInit) > +{ > + if (needInit) {
This needs to be *needInit ... > + const char *rawinitmsg; > + char *hoststr = NULL; > + char *initmsg = NULL; > + > + virLogVersionString(&rawinitmsg, &initmsg); > + outputFunc(&virLogSelf, VIR_LOG_INFO, > + __FILE__, __LINE__, __func__, > + timestamp, NULL, rawinitmsg, initmsg, > + data); > + VIR_FREE(initmsg); > + > + virLogHostnameString(&hoststr, &initmsg); > + outputFunc(&virLogSelf, VIR_LOG_INFO, > + __FILE__, __LINE__, __func__, > + timestamp, NULL, hoststr, initmsg, > + data); > + VIR_FREE(hoststr); > + VIR_FREE(initmsg); > + needInit = false; ... and this *needInit = false; Since pointers and literals evaluating to 0 actually combine without warnings in C this compiles cleanly but obviously doesn't work as expected (prints the headers along with every debug).
