Implement FreeBSD's dlfunc function to avoid ISO warnings on dlsym - thanks to drizztbsd for find public domain code :)
This commit is contained in:
parent
d0308aaecd
commit
f3888d7613
@ -29,6 +29,19 @@ typedef struct plugin
|
|||||||
|
|
||||||
static plugin_t *plugins = NULL;
|
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)
|
void rc_plugin_load (void)
|
||||||
{
|
{
|
||||||
char **files;
|
char **files;
|
||||||
@ -62,11 +75,7 @@ void rc_plugin_load (void)
|
|||||||
func = rc_xmalloc (sizeof (char *) * len);
|
func = rc_xmalloc (sizeof (char *) * len);
|
||||||
snprintf (func, len, "_%s_hook", file);
|
snprintf (func, len, "_%s_hook", file);
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
|
||||||
fptr = (int (*)(rc_hook_t, const char*)) dlfunc (h, func);
|
fptr = (int (*)(rc_hook_t, const char*)) dlfunc (h, func);
|
||||||
#else
|
|
||||||
fptr = (int (*)(rc_hook_t, const char*)) dlsym (h, func);
|
|
||||||
#endif
|
|
||||||
if (! fptr) {
|
if (! fptr) {
|
||||||
eerror ("`%s' does not expose the symbol `%s'", p, func);
|
eerror ("`%s' does not expose the symbol `%s'", p, func);
|
||||||
dlclose (h);
|
dlclose (h);
|
||||||
|
@ -12,4 +12,15 @@ void rc_plugin_load ();
|
|||||||
void rc_plugin_unload ();
|
void rc_plugin_unload ();
|
||||||
void rc_plugin_run (rc_hook_t, const char *value);
|
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
|
#endif
|
||||||
|
@ -80,8 +80,8 @@ static void setup_selinux (int argc, char **argv)
|
|||||||
* which sucks ass
|
* which sucks ass
|
||||||
* http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html
|
* http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html
|
||||||
*/
|
*/
|
||||||
selinux_run_init_old = (void (*)(void)) dlsym (lib_handle, "selinux_runscript");
|
selinux_run_init_old = (void (*)(void)) dlfunc (lib_handle, "selinux_runscript");
|
||||||
selinux_run_init_new = (void (*)(int, char **)) dlsym (lib_handle, "selinux_runscript2");
|
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 */
|
/* Use new run_init if it rc_exists, else fall back to old */
|
||||||
if (selinux_run_init_new)
|
if (selinux_run_init_new)
|
||||||
|
Loading…
Reference in New Issue
Block a user