[collectd] Static Build

Sebastian Harl sh at tokkee.org
Tue Jun 17 20:46:50 CEST 2008

Hi Jesse,

On Fri, Jun 13, 2008 at 08:33:29AM -0700, Jesse Dutton wrote:
> On Fri, Jun 13, 2008 at 1:50 AM, Sebastian Harl <sh at tokkee.org> wrote:
> > I can't think of any way to get that working with collectd unless you're
> > using a single plugin only. All plugins are implemented as shared
> > objects and the code heavily depends on that.
> There are other systems that have this same problem (e.g. linux kernel
> modules). They use a macro to expose a static module_register function
> when the module is not built-in. In the built-in case, we could mangle
> the function names so that they are unique, and use the HAVE_PLUGIN_X
> #defines to call each module_register in turn during startup.
> Thoughts?

I don't think that the calls to module_register should be hard-coded
when doing static linking - the user should still be possible to
configure which plugins are supposed to be loaded, i.e. the semantics of
collectd should still be the same.

Anyway, I think this should be doable fairly easily using the following
two steps:

 * Create a second version of plugin_load() (src/plugin.c) that handles
   the static case. That function would just have to call the
   appropriate module_register function. The problem here is, that we
   have to call that function _by_ _name_. I can currently think of two
   ways how to implement that:

   + Use dlsym() to get the address of that function. The handle that
     has to be passed to dlsym() would have to be obtained using
     dlopen(NULL, flags).

     However, I don't know if that would help in this case - I guess
     that needs some kind of shared library support by the operating
     system. Jesse, is dlopen() and dlsym() available on your system?

   + Use a lookup-table. The table would have to be generated
     dynamically at compile time depending on which plugins are to be
     built. Doing that manually (listing all plugins and using #ifdef's)
     is quite error prone, so I'd suggest to use a script to create

 * When doing a static build, rename the module_register functions to
   <plugin_name>_module_register. That would make the name unique and
   allow the function to be called by name. This should imho be handled
   by some #define like this:

     # define MODULE_REGISTER(name) void name##_module_register (void)
     # define MODULE_REGISTER(name) void module_register (void)

   Then, in the plugins use the following to define the module_register

         /* ... */

I think that should be it. Did I miss anything? Comments?

So, if we can use the dlsym() thingy, the whole patch should be about 20
lines + replacing module_register with MODULE_REGISTER in all plugins...


Sebastian "tokkee" Harl +++ GnuPG-ID: 0x8501C7FC +++ http://tokkee.org/

Those who would give up Essential Liberty to purchase a little Temporary
Safety, deserve neither Liberty nor Safety.         -- Benjamin Franklin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080617/3fa51265/attachment.pgp 

More information about the collectd mailing list