Re: [PATCH 5/6] virprocess: Passthru error from virProcessRunInForkHelper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> > ---
> >  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

Attachment: signature.asc
Description: This is a digitally signed message part.


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux