log: Guarantee the operation of %m in nbdkit_error()
commit1c230358462c349533062eda9e4072054fda0e21
authorEric Blake <eblake@redhat.com>
Thu, 29 Nov 2018 16:59:33 +0000 (29 10:59 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 29 Nov 2018 17:56:30 +0000 (29 11:56 -0600)
treed9a9ac22feea5a67157c36309f48d807e7f14739
parent9d4594ab553210c30c4e9b6dd2d221d8f66bb17f
log: Guarantee the operation of %m in nbdkit_error()

printf("%m") is a useful glibc extension, if you are sure
that errno is unchanged between the time of the actual problem
and your output message; it beats the longhand of writing
strerror(errno) yourself.  However, BSD libc does not support
the extension, and can result in awkward error messages like

pread: m

instead of an intended

pread: Input/output error

Solve the problem by probing at configure time if %m works,
(this is a runtime test, but can be overridden for testing or
cross-compiling by setting the nbdkit_cv_func_printf_percent_m
cache variable), and if not, inserting our own wrapper around
vfprintf to manually expand a single instance of %m.  (Thankfully,
it is MUCH easier to do this rewrite for %m, since it does not
consume anything from the va_list arg, than it would be for
any other % sequence where we'd have to write a full printf
parser).

As a caller is unlikely to pass multiple %m in a single format
string, I didn't bother with replacing a second instance; the
documentation updates mention this restriction.

Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
configure.ac
docs/nbdkit-filter.pod
docs/nbdkit-plugin.pod
src/internal.h
src/log.c