[libvirt] [PATCH] tpm: adapt sysfs cancel path for new TPM driver

Daniel P. Berrange berrange at redhat.com
Tue Nov 17 15:26:14 UTC 2015


On Tue, Nov 17, 2015 at 10:24:51AM -0500, Stefan Berger wrote:
> On 11/17/2015 09:24 AM, Daniel P. Berrange wrote:
> >On Tue, Nov 17, 2015 at 09:18:29AM -0500, Stefan Berger wrote:
> >>
> >>To get that path right we need to test it's availability by opening it.
> >>Unfortunately there's  problem with that now related to the test case below
> >>where, if the test is run as non-root, /dev/null will be returned, and if
> >>run as root possibly one of those constructed paths will be returned. What's
> >>the best way to fix this ?
> >The unit tests should never depend on host state, so we should
> >not run this code at all.
> >
> >You sould mock override the virTPMCreateCancelPath method entirely
> >I guess to return a fixed filename.
> 
> Great. Would you accept this code here in the mock?
> 
> +
> +char *
> +virTPMCreateCancelPath(const char *devpath)
> +{
> +    const char *dev = "/sys/class/misc/tpm0/device/cancel";
> +    size_t len = strlen(dev);
> +    char *path = malloc(len + 1);
> +
> +    (void)devpath;
> +
> +    if (path)
> +        memcpy(path, dev, len + 1);
> +
> +    return path;
> +}

What's wrong with   'return strdup(dev)' rather than strlen+malloc+memcpy ?

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list