I have an interesting problem. I'm writing a shared library which is
inserted into an alien process via LD_PRELOAD. I have almost everything
working beautifully but the library needs to get access to the exit code
before quitting. Its destructor function is definitely called after
exit() so the value must be around someplace but I do not know a way to
get it. Any ideas?

This is for Linux and Solaris. A simple test case using gcc is below.
Currently it reports "0" for the exit code but it needs to give the real
value.

Thanks,
Arch Stanton

% cat ldlab.c
---------------------------------------
#include
#include
#include

static void ldlab_init(void) __attribute__ ((constructor));
static void ldlab_fini(void) __attribute__ ((destructor));

static void
ldlab_init(void)
{
write(STDERR_FILENO, "= Starting\n", 11);
}

static void
ldlab_fini(void)
{
fprintf(stderr, "= Ending with exit code %d\n", 0); // PROBLEM!
}
---------------------------------------

% gcc -g -W -Wall -fpic -shared -o ldlab.so ldl>

% LD_PRELOAD=./ldlab.so date
= Starting
Wed Oct 1 10:50:54 EDT 2008
= Ending with exit code 0