* Richard W. M. Jones:
On Fri, Jul 17, 2020 at 01:13:00PM +0200, Florian Weimer wrote:
> * Richard W. M. Jones:
>
> > In libnbd we use sys_errlist[] to make a perror function that is safe
> > to call after fork and before exec:
> >
> >
https://github.com/libguestfs/libnbd/blob/a6ba108309d9250e5f7fe0a5d41a996...
> >
> > It looks as if glibc removed this list, which is annoying. Two
> > questions:
> >
> > (1) How can we write a fork-safe perror function?
>
> >From the glibc NEWS file:
>
> * The functions strerrorname_np and strerrordesc_np have been added. The
> strerroname_np returns error number name (e.g. "EINVAL" for EINVAL)
while
> strerrordesc_np returns string describing error number
> (e.g "Invalid argument" for EINVAL). Different than strerror,
> strerrordesc_np does not attempt to translate the return description, both
> functions return NULL for an invalid error number.
I see these defined in <string.h>. Are they async-safe (ie. safe
after fork and before exec)? If so we can use this as an alternative.
Yes, although the manual doesn't really say so.
> > (2) Why is the configure not working (it detects that
sys_errlist is
> > still available)?
> >
> >
https://github.com/libguestfs/libnbd/blob/a6ba108309d9250e5f7fe0a5d41a996...
>
> The test is broken (two type mismatches), but linking still fails for me
> in rawhide.
[Type mismatches are intentional - see how other autoconf tests are
implemented]. Well, it works for me in Rawhide :-(
configure:12994: checking for sys_errlist
configure:13007: gcc -o conftest -O2 -g -pipe -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong
-grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic
-fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wl,-z,relro
-Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld conftest.c
>&5
conftest.c: In function 'main':
conftest.c:40:35: warning: initialization of 'char *' from incompatible pointer
type 'int *' [-Wincompatible-pointer-types]
40 | extern int sys_errlist; char *p = &sys_errlist;
| ^
conftest.c:40:31: warning: unused variable 'p' [-Wunused-variable]
40 | extern int sys_errlist; char *p = &sys_errlist;
| ^
configure:13007: $? = 0
configure:13012: result: yes
This is with glibc-2.31.9000-19.fc33.x86_64. I can see that
sys_errlist is a symbol still in /lib64/libc.so.
Yes, but it's a compat symbol, so not available for linking.
What is the test file autoconf feeds to the compiler?
Thanks,
Florian