Ian Donnelly: How-To: Write a Plug-In (Part 1, The Basics)
Hi Everybody!
For the first part of my Plug-In tutorial, I am going to cover the basic overview of an elektra plug-in. This post just explains the basic format and functions of an Elektra plug-in, specifically a storage plug-in (this will be the focus of my tutorial).
All plug-ins use the same basic interface. This interface consists of five basic functions, elektraPluginOpen, elektraPluginGet, elektraPluginSet, elektraPluginError, and elektraPluginClose. The developer replaces Plugin with the name of their plugin. So in the case of my plugin, the names of these functions would be elektraLineOpen(), elektraLineGet(), elektraLineSet(), elektraLineError(), and elektraLineClose(). Additionally, there is one more function called ELEKTRA_PLUGIN_EXPORT(plugin), where once again Plugin should be replaced with the name of the plug-in, this time in lower-case. So for my line plugin this function would be ELEKTRA_PLUGIN_EXPORT(line).
The KDB relies on the first five functions for interacting with configuration files stored in the key database. Calls for kdbGet() and kdbClose() will call the functions elektraPluginGet() and elektraPluginClose() respectively for the plugin that was used to mount the configuration data. kdbSet() calls elektraPluginSet() but also elektraPluginError() when an error occurs. elektraPluginOpen() is called before the first call to elektraPluginGet() or elektraPluginSet(). These functions serve different purposes that allow the plug-in to work:
from within the plugins directory. Afterwards two important things are left to be done:
Ian S. Donnelly
- elektraPluginOpen() is designed to allow each plug-in to do initialization if necessary.
- elektraPluginGet() is designed to turn information from a configuration file into a usable KeySet, this is technically the only function that is REQUIRED in a plug-in.
- elektraPluginSet() is designed to store the information from the keyset back into a configuration file.
- elektraPluginError() is designed to allow proper rollback of operations if needed and is called if any plugin fails during the set operation. This allows exception-safety.
- elektraPluginClose() is used to free resources that might be required for the plug-in.
- ELEKTRA_PLUGIN_EXPORT(Plugin) simply lets Elektra know that the plug-in exists and what the name of the above functions are.
../../scripts/copy-template line
from within the plugins directory. Afterwards two important things are left to be done:
- remove all functions (and their exports) from the plugin that are not needed. For example not every plugin actually makes use of the elektraPluginOpen() function.
- provide a basic contract as described above
Ian S. Donnelly
Yes, I've been bragging about the
Yesterday I spent a while looking at the

This is time again for my annual report about the number of developers per
country.
This is now the sixth edition of this report. Former editions:
I'll be moving places twice within the next month and as I'm hosting the
machine that generates the data, I'll temporarily suspend the
Finally I find the mood to do this, a process which started 5 years ago in