[PATCH 5/6] virprocess: Passthru error from virProcessRunInForkHelper
Pino Toscano
ptoscano at redhat.com
Tue Mar 24 10:52:34 UTC 2020
On Tuesday, 24 March 2020 11:48:17 CET Daniel P. Berrangé wrote:
> On Wed, Mar 18, 2020 at 06:32:15PM +0100, Michal Privoznik wrote:
> > When running a function in a forked child, so far the only thing
> > we could report is exit status of the child and the error
> > message. However, it may be beneficial to the caller to know the
> > actual error that happened in the child.
> >
> > Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> > ---
> > build-aux/syntax-check.mk | 2 +-
> > src/util/virprocess.c | 51 ++++++++++++++++++++++++++++++++++++---
> > tests/commandtest.c | 43 +++++++++++++++++++++++++++++++++
> > 3 files changed, 91 insertions(+), 5 deletions(-)
> > diff --git a/tests/commandtest.c b/tests/commandtest.c
> > index a64aa9ad33..f4a2c67c05 100644
> > --- a/tests/commandtest.c
> > +++ b/tests/commandtest.c
> > @@ -1257,6 +1257,48 @@ static int test27(const void *unused G_GNUC_UNUSED)
> > }
> >
> >
> > +static int
> > +test28Callback(pid_t pid G_GNUC_UNUSED,
> > + void *opaque G_GNUC_UNUSED)
> > +{
> > + virReportSystemError(ENODATA, "%s", "some error message");
> > + return -1;
> > +}
> > +
> > +
> > +static int
> > +test28(const void *unused G_GNUC_UNUSED)
> > +{
> > + /* Not strictly a virCommand test, but this is the easiest place
> > + * to test this lower-level interface. */
> > + virErrorPtr err;
> > +
> > + if (virProcessRunInFork(test28Callback, NULL) != -1) {
> > + fprintf(stderr, "virProcessRunInFork did not fail\n");
> > + return -1;
> > + }
> > +
> > + if (!(err = virGetLastError())) {
> > + fprintf(stderr, "Expected error but got nothing\n");
> > + return -1;
> > + }
> > +
> > + if (!(err->code == VIR_ERR_SYSTEM_ERROR &&
> > + err->domain == 0 &&
> > + STREQ(err->message, "some error message: No data available") &&
> > + err->level == VIR_ERR_ERROR &&
> > + STREQ(err->str1, "%s") &&
> > + STREQ(err->str2, "some error message: No data available") &&
> > + err->int1 == ENODATA &&
> > + err->int2 == -1)) {
> > + fprintf(stderr, "Unexpected error object\n");
> > + return -1;
> > + }
>
> This new test fails on FreeBSD
>
> $ VIR_TEST_DEBUG=1 VIR_TEST_RANGE=28 ./commandtest
> TEST: commandtest
> 28) Command Exec test28 test ... Unexpected error object
> libvirt: error : some error message: Input/output error
> FAILED
>
>
> IIUC the problem here is that the STREQ check is assuming that the
> ENODATA errno results in the string "No data available". The strings
> are not standardized by POSIX AFAIK, so C libraries can use any reasonable
> text for them. So this check is not portable.
>
> Perhaps its enough to use STRPREFIX(err->str2, "some error message:") ?
Or maybe use g_strerror to get the error message of ENODATA, and
compare it to the actual message got in the test.
--
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200324/b9a4476e/attachment-0001.sig>
More information about the libvir-list
mailing list