Bug#839101: cowdancer: Keep open() async-signal-safe
Thorsten Glaser
tg at mirbsd.de
Wed Sep 28 22:25:46 UTC 2016
Jack Bates dixit:
>A) Call dlsym() early, before anything calls open(). Not possible
> because even if you managed to call dlsym() before anything else,
> dlsym() itself might call open() before it was done initializing :-(
>
>B) Avoid dlsym() altogether. What are the options in this case?
>
> 1) Use sys_open() instead of dlsym(RTLD_NEXT, "open)
How about a combination of both?
Something like this (pseudo code, mostly):
static void initialise_open(void) __attribute__((__constructor__));
static uint8_t open_initialised = 0;
int
open(const char *path, int flags, mode_t mode)
{
if (!open_initialised)
return (sys_open(path, flags, mode));
/* current code with dlsym’s result */
}
static void
initialise_open(void)
{
/* call dlsym, which is now allowed to call open() */
/* store its result */
open_initialised = 1;
}
Of course, I probably ought to better go to bed, but someone
might make something off this. Also, completely untested, modulo
that I have an application in which these constructors work, in
plain GCC (no C++).
Good night,
//mirabilos
--
“ah that reminds me, thanks for the stellar entertainment that you and certain
other people provide on the Debian mailing lists │ sole reason I subscribed to
them (I'm not using Debian anywhere) is the entertainment factor │ Debian does
not strike me as a place for good humour, much less German admin-style humour”
More information about the Pbuilder-maint
mailing list