[Libguestfs] [PATCH libnbd] tests: Add a test of nbd_{set, get}_socket_activation_name
Eric Blake
eblake at redhat.com
Mon May 8 13:50:27 UTC 2023
On Mon, May 08, 2023 at 09:11:03AM +0200, Laszlo Ersek wrote:
> > +
> > + /* nbdkit doesn't know anything about socket activation names, but
> > + * the LISTEN_FDNAMES environment variable should appear in the
> > + * debug output.
> > + */
> > + assert (system ("grep 'debug.*LISTEN_FDNAMES=hello' " DEBUG_FILE) == 0);
>
> I didn't remember the return value of system(); I've now tried to read
> up (both the Linux man page and POSIX), and my head is spinning a bit :)
>
> It seems like we should do something like:
>
> int rc;
>
> rc = system ("grep 'debug.*LISTEN_FDNAMES=hello' " DEBUG_FILE);
> assert (rc != -1 && WIFEXITED (rc) && WEXITSTATUS (rc) == 0);
Technically true. But all existing implementations tend to encode
exit staus as a 16-bit value in one of two configurations:
status last: abnormal byte, status byte
status first: status byte, abnormal byte
where WIFEXITED() is a macro that returns 1 if the status byte is 0,
and WEXITSTAUTS() is a macro that masks off the abnormal byte to
expose just the status byte shifted into the usual 8-bit position.
It's not required by POSIX, but you can generally get away with
relying on 'rc==0' implies 'WIFEXITED(rc) && WEXITSTATUS(rc)==0' on
all platforms.
>
> Also, should we invoke this "grep" with "-sq" as well (at least "-q")?
> Or do we want the match to show up in the test suite log?
Having more rather than less information in the logs can be useful
when debugging CI failures.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
More information about the Libguestfs
mailing list