server/crypto.c: Improve error messages in crypto_sendmaster
commit45b72f5bd8fc1b475fa130d06c86cd877bf595d5
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 10 Mar 2023 09:59:15 +0000 (10 09:59 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 10 Mar 2023 10:08:50 +0000 (10 10:08 +0000)
treee9b2c1f687bb9f34732d7eb2bc784a75705a371e
parent9fb6ca6b0492c427809398b330e315cd9e76c5a9
server/crypto.c: Improve error messages in crypto_send

The ->send method is expected to set errno.  We didn't set it
explicitly before, although it was usually set implicitly.  Let's
improve this.

Firstly never lose the real error message (from gnutls) so always call
nbdkit_error (... gnutls_strerror ...)  along error paths, even though
that sometimes means we'll get double errors because the caller will
also call nbdkit_error (... "%m" ...).

Secondly make sure errno is set to something on error.  Surround each
gnutls call with errno = 0; ... if (errno == 0) errno = EIO.  This
means we'll capture the underlying syscall error if there was one, but
if there wasn't one then we'll always return with errno set on error
paths out of the function.
server/crypto.c