From f3888d76138c9f347e118e3942d5a1dd49b351ff Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 14 May 2007 19:50:13 +0000 Subject: [PATCH] Implement FreeBSD's dlfunc function to avoid ISO warnings on dlsym - thanks to drizztbsd for find public domain code :) --- src/rc-plugin.c | 17 +++++++++++++---- src/rc-plugin.h | 11 +++++++++++ src/runscript.c | 4 ++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/rc-plugin.c b/src/rc-plugin.c index 2c8bfff5..66ffeb5c 100644 --- a/src/rc-plugin.c +++ b/src/rc-plugin.c @@ -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); diff --git a/src/rc-plugin.h b/src/rc-plugin.h index b4391ad0..15d46213 100644 --- a/src/rc-plugin.h +++ b/src/rc-plugin.h @@ -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 diff --git a/src/runscript.c b/src/runscript.c index ecbe34cc..82484f13 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -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)