#include <pthread.h>
#include <dlfcn.h>
#include <dirent.h>

void *
lookup_thread (void *handle)
{
	while (1)
		dlsym (handle, "main");

	return NULL;
}

int
main (int argc, char **argv)
{
	pthread_t loader;
	DIR *d;
	struct dirent *dent;
	char *so;

	pthread_create (&loader, NULL, lookup_thread, dlopen (NULL, RTLD_NOW));

	d = opendir ("/usr/lib");
	while ((dent = readdir (d))) {
		so = strstr (dent->d_name, ".so");
		if (!so || so[3])
			continue;

		printf ("%s\n", dent->d_name);
		dlopen (dent->d_name, RTLD_NOW | RTLD_GLOBAL);
	}

	printf ("Oh well. Worse luck next time!\n");
	return 0;
}
