reductions, build fixes
This commit is contained in:
parent
ff11966791
commit
12f03e20c4
@ -1,4 +1,4 @@
|
|||||||
CFLAGS += -shared -fPIE
|
CFLAGS += -shared -fPIC
|
||||||
|
|
||||||
libplug.so: plug.o
|
libplug.so: plug.o
|
||||||
${LINK.c} $+ -o $@
|
${LINK.c} $+ -o $@
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#ifndef PLUG_H_
|
#ifndef PLUG_H_
|
||||||
|
|
||||||
|
#define _QUOTE(name) #name
|
||||||
|
#define QUOTE(name) _QUOTE(name)
|
||||||
#define BIND(lib, func, func_name) *(void **) (&func) = dlsym(lib, func_name)
|
#define BIND(lib, func, func_name) *(void **) (&func) = dlsym(lib, func_name)
|
||||||
|
#define PLUGIN(lib, x) BIND(lib, x, QUOTE(x))
|
||||||
|
|
||||||
typedef void (*plug_t)(void);
|
typedef void (*plug_t)(void);
|
||||||
|
plug_t plug;
|
||||||
static plug_t plug;
|
|
||||||
|
|
||||||
#define PLUG_H_
|
#define PLUG_H_
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
CPPFLAGS += -I../plug -L../plug
|
CPPFLAGS += -I../plug -L../plug
|
||||||
|
LDLIBS += -ldl
|
||||||
|
|
||||||
plugin: main.o
|
plugin: main.o
|
||||||
${LINK.c} $+ -o $@ ${LDLIBS}
|
${LINK.c} $+ -o $@ ${LDLIBS}
|
||||||
|
@ -12,19 +12,18 @@ main (void)
|
|||||||
void * libplug = NULL;
|
void * libplug = NULL;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (libplug) { dlclose(libplug); }
|
|
||||||
libplug = dlopen(libplug_fn, RTLD_NOW);
|
libplug = dlopen(libplug_fn, RTLD_NOW);
|
||||||
BIND(libplug, plug, "plug");
|
|
||||||
if (!libplug)
|
if (!libplug)
|
||||||
{ fprintf(stderr, "ERR: Cannot load dynamic library %s: %s\n", libplug_fn, dlerror()); }
|
{ fprintf(stderr, "ERR: Cannot load dynamic library %s: %s\n", libplug_fn, dlerror()); }
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*(void **) (&plug) = dlsym(libplug, "plug");
|
PLUGIN(libplug, plug);
|
||||||
printf("frame %d: ", x++);
|
printf("frame %d: ", x++);
|
||||||
if (plug)
|
if (plug)
|
||||||
{ plug(); }
|
{ plug(); }
|
||||||
else
|
else
|
||||||
{ fprintf(stderr, "ERR: Cannot find %s symbol in %s: %s\n", "plug", libplug_fn, dlerror()); }
|
{ fprintf(stderr, "ERR: Cannot find %s symbol in %s: %s\n", "plug", libplug_fn, dlerror()); }
|
||||||
|
dlclose(libplug);
|
||||||
}
|
}
|
||||||
sleep(2);
|
sleep(2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user