Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
kdb/gopts: add gopts as global procstorage plugin by default
Browse files Browse the repository at this point in the history
the plugin is disabled by default and a very quick and dirty temporary(!) solution to enable it is provided
  • Loading branch information
kodebach committed Mar 22, 2019
1 parent a6deb05 commit 0f6eaf3
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/bindings/cpp/include/kdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class KDB
virtual inline int set (KeySet & returned, std::string const & keyname);
virtual inline int set (KeySet & returned, Key & parentKey);

inline ckdb::KDB * getKDB ()
{
return handle;
}

private:
ckdb::KDB * handle; ///< holds an kdb handle
};
Expand Down
1 change: 1 addition & 0 deletions src/include/kdbproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ int keyRel2 (const Key * k1, const Key * k2, KeyRelType which);
Key * keyAsCascading (const Key * key);
int keyGetLevelsBelow (const Key * k1, const Key * k2);

int elektraEnableOptionsProcessing (KDB * handle, int enabled);

#ifdef __cplusplus
}
Expand Down
8 changes: 8 additions & 0 deletions src/libs/elektra/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ KeySet * elektraDefaultGlobalConfig (void)
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#0/placements", KEY_VALUE, "spec", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#0/placements/get", KEY_VALUE, "postgetstorage", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#0/placements/set", KEY_VALUE, "presetstorage", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#1", KEY_VALUE, "gopts", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#1/placements", KEY_VALUE, "gopts", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#1/placements/get", KEY_VALUE, "procgetstorage", KEY_END),
#else
keyNew ("system/elektra/globalplugins/postcommit/user/plugins", KEY_VALUE, "", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#0", KEY_VALUE, "gopts", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#0/placements", KEY_VALUE, "gopts", KEY_END),
keyNew ("system/elektra/globalplugins/postcommit/user/plugins/#0/placements/get", KEY_VALUE, "procgetstorage", KEY_END),
#endif
keyNew ("system/elektra/globalplugins/postgetstorage", KEY_VALUE, "list", KEY_END),
keyNew ("system/elektra/globalplugins/postrollback", KEY_VALUE, "list", KEY_END),
Expand Down
13 changes: 13 additions & 0 deletions src/libs/proposal/proposal.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,19 @@ int keyRel2 (const Key * key, const Key * check, KeyRelType which)
return retVal;
}

/**
* Sets whether automatic options processing via gopts is enabled.
*
* @param handle contains internal information of @link kdbOpen() opened @endlink key database
* @param enabled (boolean) whether options processing should be enabled
*
* @retval 0 on succes
* @retval -1 on error
*/
int elektraEnableOptionsProcessing (KDB * handle, int enabled)
{
return ksAppendKey (handle->global, keyNew ("user/gopts/enabled", KEY_VALUE, enabled ? "1" : "0", KEY_END)) < 0 ? -1 : 0;
}

/**
* @}
Expand Down
12 changes: 11 additions & 1 deletion src/plugins/gopts/gopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void cleanupEnvp (char ** envp);
#endif


int elektraGOptsGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * parentKey)
int elektraGOptsGet (Plugin * handle, KeySet * returned, Key * parentKey)
{
if (!elektraStrCmp (keyName (parentKey), "system/elektra/modules/gopts"))
{
Expand All @@ -49,6 +49,16 @@ int elektraGOptsGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Key * pa
return ELEKTRA_PLUGIN_STATUS_SUCCESS;
}

KeySet * globalKS = elektraPluginGetGlobalKeySet (handle);
if (globalKS != NULL)
{
Key * enabled = ksLookupByName (globalKS, "user/gopts/enabled", 0);
if (enabled == NULL || strcmp (keyString (enabled), "1") != 0)
{
return ELEKTRA_PLUGIN_STATUS_NO_UPDATE;
}
}

char ** argv = NULL;
int argc = loadArgs (&argv);
char ** envp = loadEnvp ();
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
typedef enum
{
preGetStorage = 0,
procGetStorage,
postGetStorage,
postGetCleanup,
getEnd
Expand Down Expand Up @@ -64,12 +65,12 @@ typedef struct

ErrPlacements errPlacements[2]; // prerollback and postrollback
SetPlacements setPlacements[4]; // presetstorage, presetcleanup, precommit and postcommit
GetPlacements getPlacements[3]; // pregetstorage, postgetstorage, postgetclenaup
GetPlacements getPlacements[4]; // pregetstorage, procgetstorage, postgetstorage, postgetclenaup

// each keyset contains the list of plugin names for a given placement
KeySet * setKS[4];
KeySet * errKS[2];
KeySet * getKS[3];
KeySet * getKS[4];
KeySet * plugins;
KeySet * modules;

Expand Down Expand Up @@ -129,7 +130,7 @@ static int listParseConfiguration (Placements * placements, KeySet * config)
if (sub)
{
const char * getString = keyString (sub);
const char * getStrings[] = { "pregetstorage", "postgetstorage", "postgetcleanup" };
const char * getStrings[] = { "pregetstorage", "procgetstorage", "postgetstorage", "postgetcleanup" };
GetPlacements getPlacement = preGetStorage;
while (getPlacement != getEnd)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tools/kdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (BUILD_SHARED)
add_executable (kdb $<TARGET_OBJECTS:kdb-objects>)
add_dependencies (kdb kdberrors_generated elektra_error_codes_generated)

target_link_libraries (kdb elektra-core elektra-kdb elektratools)
target_link_libraries (kdb elektra-core elektra-kdb elektratools elektra-proposal)

install (TARGETS kdb DESTINATION bin)
endif (BUILD_SHARED)
Expand Down
5 changes: 5 additions & 0 deletions src/tools/kdb/ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
#include <kdb.hpp>
#include <keysetio.hpp>

#include <modules.hpp>

#include <kdbproposal.h>

using namespace kdb;
using namespace kdb::tools;
using namespace std;

LsCommand::LsCommand () : kdb (root)
Expand Down

0 comments on commit 0f6eaf3

Please sign in to comment.