[libvirt PATCH] src: remove WITH_GNUTLS usage

Daniel P. Berrangé berrange at redhat.com
Wed Jan 22 16:47:03 UTC 2020


On Wed, Jan 22, 2020 at 05:33:02PM +0100, Pavel Hrdina wrote:
> Since commit <60d9ad6f1e42618fce10baeb0f02c35e5ebd5b24> we require
> GnuTLS so it doesn't make sense to ifdef the code.
> 
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> ---
>  src/libvirt.c              |  6 +-----
>  src/remote/remote_driver.c | 19 -------------------
>  src/rpc/virnetclient.c     | 20 ++++----------------
>  src/rpc/virnetclient.h     |  8 +-------
>  src/rpc/virnetsocket.c     | 16 ----------------
>  src/rpc/virnetsocket.h     |  6 +-----
>  src/util/virrandom.c       | 36 ++----------------------------------
>  7 files changed, 9 insertions(+), 102 deletions(-)

...

> diff --git a/src/util/virrandom.c b/src/util/virrandom.c
> index 39ac36a76e..eae7f3db3c 100644
> --- a/src/util/virrandom.c
> +++ b/src/util/virrandom.c
> @@ -24,10 +24,8 @@
>  #include <fcntl.h>
>  #include <sys/stat.h>
>  #include <sys/types.h>
> -#ifdef WITH_GNUTLS
> -# include <gnutls/gnutls.h>
> -# include <gnutls/crypto.h>
> -#endif
> +#include <gnutls/gnutls.h>
> +#include <gnutls/crypto.h>
>  
>  #include "virrandom.h"
>  #include "virthread.h"

There's a #define of RANDOM_SOURCE that I believe you can
drop too....

> @@ -116,7 +114,6 @@ int
>  virRandomBytes(unsigned char *buf,
>                 size_t buflen)

And the API docs for this are talking about RANDOM_SOURCE
instead of GNUTLS (pre-existing problem, but reasonabl
to fix now)

>  {
> -#if WITH_GNUTLS
>      int rv;
>  
>      /* Generate the byte stream using gnutls_rnd() if possible */
> @@ -127,35 +124,6 @@ virRandomBytes(unsigned char *buf,
>          return -1;
>      }
>  
> -#else /* !WITH_GNUTLS */
> -
> -    int fd;
> -
> -    if ((fd = open(RANDOM_SOURCE, O_RDONLY)) < 0) {
> -        virReportSystemError(errno,
> -                             _("unable to open %s"),
> -                             RANDOM_SOURCE);
> -        return -1;
> -    }
> -
> -    while (buflen > 0) {
> -        ssize_t n;
> -
> -        if ((n = saferead(fd, buf, buflen)) <= 0) {
> -            virReportSystemError(errno,
> -                                 _("unable to read from %s"),
> -                                 RANDOM_SOURCE);
> -            VIR_FORCE_CLOSE(fd);
> -            return n < 0 ? -errno : -ENODATA;
> -        }
> -
> -        buf += n;
> -        buflen -= n;
> -    }
> -
> -    VIR_FORCE_CLOSE(fd);
> -#endif /* !WITH_GNUTLS */
> -
>      return 0;

With the above minor changes

Reviewed-by: Daniel P. Berrangé <berrange at redhat.com> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list