On Fri, Jan 20, 2023 at 16:03:08 -0600, Jonathon Jongsma wrote: > This code can be used by the nbdkit implementation for reading back > filtered log data for error reporting. Move it to qemuLogContext so that > it can be shared. Renamed to qemuLogContextReadFiltered(). > > Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> > --- > src/qemu/qemu_logcontext.c | 65 ++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_logcontext.h | 3 ++ > src/qemu/qemu_process.c | 67 +------------------------------------- > 3 files changed, 69 insertions(+), 66 deletions(-) > @@ -236,6 +237,70 @@ qemuLogContextRead(qemuLogContext *ctxt, > } > > > +/** > + * qemuLogContextFilter: Read and filter log for relevant messages > + * @ctxt: the domain log context > + * @msg: pointer to buffer to store the read messages in > + * @max: maximum length of the message returned in @msg after filtering > + * > + * Reads log output from @ctxt and filters it. Skips messages not produced by > + * the target executable or irrelevant messages. If @max is not zero, @buf will > + * contain at most @max characters from the end of the log and @buf will start > + * after a new line if possible. > + */ > +int > +qemuLogContextReadFiltered(qemuLogContext *ctxt, > + char **msg, > + size_t max) broken formatting > +{ > + char *buf; > + char *eol; > + char *filter_next; > + size_t skip; > + ssize_t got; [...] > qemuLogContextGetWriteFD(qemuLogContext *ctxt) > { > diff --git a/src/qemu/qemu_logcontext.h b/src/qemu/qemu_logcontext.h > index c6dbf3cb84..669a05ae97 100644 > --- a/src/qemu/qemu_logcontext.h > +++ b/src/qemu/qemu_logcontext.h > @@ -32,6 +32,9 @@ int qemuLogContextWrite(qemuLogContext *ctxt, > const char *fmt, ...) G_GNUC_PRINTF(2, 3); > ssize_t qemuLogContextRead(qemuLogContext *ctxt, > char **msg); > +int qemuLogContextReadFiltered(qemuLogContext *ctxt, > + char **msg, > + size_t max); broken formatting > int qemuLogContextGetWriteFD(qemuLogContext *ctxt); > void qemuLogContextMarkPosition(qemuLogContext *ctxt); Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>