Implement FreeBSD's dlfunc function to avoid ISO warnings on dlsym - thanks to drizztbsd for find public domain code :)

This commit is contained in:
Roy Marples 2007-05-14 19:50:13 +00:00
parent d0308aaecd
commit f3888d7613
3 changed files with 26 additions and 6 deletions

View File

@ -29,6 +29,19 @@ typedef struct plugin
static plugin_t *plugins = NULL;
#ifndef __FreeBSD__
dlfunc_t dlfunc (void * __restrict handle, const char * __restrict symbol)
{
union {
void *d;
dlfunc_t f;
} rv;
rv.d = dlsym (handle, symbol);
return (rv.f);
}
#endif
void rc_plugin_load (void)
{
char **files;
@ -62,11 +75,7 @@ void rc_plugin_load (void)
func = rc_xmalloc (sizeof (char *) * len);
snprintf (func, len, "_%s_hook", file);
#ifdef __FreeBSD__
fptr = (int (*)(rc_hook_t, const char*)) dlfunc (h, func);
#else
fptr = (int (*)(rc_hook_t, const char*)) dlsym (h, func);
#endif
if (! fptr) {
eerror ("`%s' does not expose the symbol `%s'", p, func);
dlclose (h);

View File

@ -12,4 +12,15 @@ void rc_plugin_load ();
void rc_plugin_unload ();
void rc_plugin_run (rc_hook_t, const char *value);
/* dlfunc defines needed to avoid ISO errors. FreeBSD has this right :) */
#ifndef __FreeBSD__
struct __dlfunc_arg {
int __dlfunc_dummy;
};
typedef void (*dlfunc_t) (struct __dlfunc_arg);
dlfunc_t dlfunc (void * __restrict handle, const char * __restrict symbol);
#endif
#endif

View File

@ -80,8 +80,8 @@ static void setup_selinux (int argc, char **argv)
* which sucks ass
* http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html
*/
selinux_run_init_old = (void (*)(void)) dlsym (lib_handle, "selinux_runscript");
selinux_run_init_new = (void (*)(int, char **)) dlsym (lib_handle, "selinux_runscript2");
selinux_run_init_old = (void (*)(void)) dlfunc (lib_handle, "selinux_runscript");
selinux_run_init_new = (void (*)(int, char **)) dlfunc (lib_handle, "selinux_runscript2");
/* Use new run_init if it rc_exists, else fall back to old */
if (selinux_run_init_new)