Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opts plugin #2471

Merged
merged 41 commits into from Apr 2, 2019
Merged

Opts plugin #2471

Changes from 36 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cb4b2a1
gopts: global opts plugin basics
kodebach Feb 12, 2019
ed5c798
gopts: basic implementations
kodebach Mar 3, 2019
4e4a5af
gopts: finish implementation
kodebach Mar 8, 2019
19b420d
gopts: documentation
kodebach Mar 8, 2019
da908a0
gopts: fix win32
kodebach Mar 8, 2019
f9860a6
gopts: fix unitialized error
kodebach Mar 10, 2019
4c4d812
gopts: fix formatting
kodebach Mar 10, 2019
c46fc89
gopts: fix formatting
kodebach Mar 10, 2019
f77c480
gopts: fix memleak
kodebach Mar 12, 2019
b5f98ff
gopts: incorporate review
kodebach Mar 12, 2019
6ca1fb1
gopts: documentation
kodebach Mar 12, 2019
7bc960d
gopts: fix formatting
kodebach Mar 12, 2019
aeb860d
gopts: fix LD_LIBRARY_PATH
kodebach Mar 12, 2019
197c785
gopts: improve test error
kodebach Mar 14, 2019
4f24207
mathcheck: fix shell test
kodebach Mar 21, 2019
d8faf43
kdb: fix kdbGet global postgetstorage parent key
kodebach Mar 21, 2019
ef896ca
gopts: fix test
kodebach Mar 21, 2019
4448503
gopts: fix testapp
kodebach Mar 21, 2019
79ceb9e
multifile: fix shell test
kodebach Mar 21, 2019
24a5885
kdb: add procgetstorage global position
kodebach Mar 21, 2019
dfb41d6
kdb/gopts: add gopts as global procstorage plugin by default
kodebach Mar 22, 2019
8925478
list: fix placements
kodebach Mar 22, 2019
de7bab3
tests: fix testshell_markdown_tutorial_validation
kodebach Mar 22, 2019
74b6308
kdb: fix global mount config
kodebach Mar 24, 2019
71bacc8
kdb: kdbEnsure
kodebach Mar 27, 2019
08f0cef
kdb: remove gopts from default global plugins
kodebach Mar 27, 2019
65130e5
kdb: fix tests
kodebach Mar 27, 2019
cb74c10
kdb: add tests for kdbEnsure and fix bugs
kodebach Mar 27, 2019
aa7e40f
notification: use kdbEnsure in libnotification
kodebach Mar 27, 2019
7370a5f
kdb: fix tests
kodebach Mar 27, 2019
844f566
kdb: fix tests
kodebach Mar 28, 2019
b81e6a0
kdb: fix icheck
kodebach Mar 28, 2019
c79c67d
kdb: fix memleak
kodebach Mar 28, 2019
9f72f93
kdb: fix missing return
kodebach Mar 28, 2019
41ee812
kdb: rename elektraFindGlobalPlugin to elektraPluginFindGlobal
kodebach Mar 28, 2019
71076e4
doc: update documentation
kodebach Mar 28, 2019
a5dbd40
kdb: changes from reviews
kodebach Mar 31, 2019
31e9534
gopts: add example and fix problems
kodebach Mar 31, 2019
6767523
cmake: fix cmake_policy
kodebach Mar 31, 2019
f078edf
opts: review improvements
kodebach Apr 1, 2019
d4fe121
opts: fix formatting
kodebach Apr 1, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -12,7 +12,7 @@ function (add_lib name)

if (BUILD_SHARED)
add_library (elektra-${name} SHARED ${ARG_SOURCES})
add_dependencies (elektra-${name} kdberrors_generated elektra_error_codes_generated)
add_dependencies (elektra-${name} kdberrors_generated elektra_error_codes_generated ${ARG_LINK_ELEKTRA})

target_link_libraries (elektra-${name} elektra-core ${ARG_LINK_ELEKTRA})
endif (BUILD_SHARED)
@@ -51,7 +51,25 @@ the `type` plugin will ignore the key. We now also support converting enum value
To switch from `boolean` to the new `type`, you don't have to do anything, if you used the default config. If you used a custom configuration
please take a look at the [README](https://www.libelektra.org/plugins/type).

### <<HIGHLIGHT2>>
### kdbEnsure

`kdbEnsure` is a new function in `elektra-kdb`. It can be used to ensure that a KDB instance meets certain conditions specified in a

This comment has been minimized.

Copy link
@markus2330

markus2330 Mar 30, 2019

Contributor

conditions -> clauses (2x)

contract. In principle this a very powerful tool that may be used for a lot of things. For now it only supports a few conditions concerning
plugins:

- You can specify that a plugin should be mounted globally. This is can for example be used to enable the new [gopts](#gopts) plugin.

This comment has been minimized.

Copy link
@mpranj

mpranj Mar 30, 2019

Member

"This is can for example" -> "This can for example"

- Conversely you can also define that a plugin should not be mounted globally, e.g. to disable the `spec` plugin, which is enabled by default.
- Additionally you may want to enforce that a global plugin uses a certain configuration. For this case you can specify that the plugin
should be remounted, i.e. unmounted and immediately mounted again.
- In future non-global plugins will support the same features. But because of the different architecture involved, for now only unmounting

This comment has been minimized.

Copy link
@markus2330

markus2330 Mar 30, 2019

Contributor

No need to mention it. We might or might not add it.

non-global plugins is supported.

All changes made by `kdbEnsure` are purely temporary. They will only apply to the KDB handle passed to the function.

IMPORTANT: `kdbEnsure` only works, if the `list` plugin is mounted in all appropriate global positions.

Note: `kdbEnsure` right now ignores the `infos/recommends` and `infos/needs` metadata of plugins, so you have to explicitly take care of
dependencies. _(Klemens Böswirth)_

### <<HIGHLIGHT2>>

@@ -155,6 +173,15 @@ The following section lists news about the [modules](https://www.libelektra.org/

- We fixed an incorrect format specifier in a call to the `syslog` function. _(René Schwaiger)_

### gOpts

- The [gopts](https://www.libelektra.org/plugins/gopts) plugin simply retrieves the values of `argc`, `argv` and `envp` needed for
[`elektraGetOpts`](https://www.libelektra.org/tutorials/command-line-options) and then makes the call. It is intended to be used as a
global plugin, so that command-line options are automatically parsed when `kdbGet` is called. _(Klemens Böswirth)_
- The plugin works under WIN32 (via `GetCommandLineW` and `GetEnvironmentString`), MAC_OSX (`_NSGetArgc`, `_NSGetArgv`) and any system that
either has a `sysctl(3)` function that accepts `KERN_PROC_ARGS` (e.g. FreeBSD) or when `procfs` is mounted and either `/proc/self` or
`/proc/curproc` refers to the current process. If you need support for any other systems, feel free to add an implementation.

## Libraries

The text below summarizes updates to the [C (and C++)-based libraries](https://www.libelektra.org/libraries/readme) of Elektra.
@@ -171,7 +198,7 @@ compiled against an older 0.8 version of Elektra will continue to work

### Core

- <<TODO>>
- `kdbGet` now calls global postgetstorage plugins with the parent key passed to `kdbGet`, instead of a random mountpoint. _(Klemens Böswirth)_

This comment has been minimized.

Copy link
@mpranj

This comment has been minimized.

Copy link
@kodebach

kodebach Mar 30, 2019

Author Contributor

One thing I noticed (but didn't look into): At least some errors returned from global plugins are suppressed by kdbGet. You may want to look into that while working on #2457.

This comment has been minimized.

Copy link
@mpranj

mpranj Mar 30, 2019

Member

Yep, we didn't even use return values until #2307. The global plugin implementation needs to be re-worked and tested properly, so that it matches the proposal.

- <<TODO>>
- <<TODO>>

@@ -318,6 +318,7 @@ Before we look further let us undo the modifications to the key database.
```sh
kdb rm -r spec/tests/tutorial
kdb rm -r system/tests/tutorial
kdb rm -rf user/tests/tutorial
kdb umount spec/tests/tutorial
kdb umount /tests/tutorial
kdb rm -rf spec
@@ -121,9 +121,29 @@ class KDBException : public Exception
return "User Exception: KDB";
}

private:
protected:
Key m_key;
};

class ContractException : public KDBException
{
public:
explicit ContractException (Key key) : KDBException (key)
{
}

~ContractException () noexcept override = default;

const char * what () const noexcept override
{
if (!m_key)
{
return "Malformed contract";
}
return KDBException::what ();
}
};

} // namespace kdb


@@ -56,6 +56,8 @@ class KDB
virtual inline int set (KeySet & returned, std::string const & keyname);
virtual inline int set (KeySet & returned, Key & parentKey);

inline int ensure (const KeySet & contract, Key & parentKey);

private:
ckdb::KDB * handle; ///< holds an kdb handle
};
@@ -232,6 +234,33 @@ inline int KDB::set (KeySet & returned, Key & parentKey)
return ret;
}

/**
* Ensures that the conditions defined in @p contract are met by this KDB.
*
* @see ckdb::kdbEnsure()
*
* @param contract The contract to ensure.
* @param parentKey The parentKey to use.
*
* @throw KDBException if there were problems with the contract or the database
* @throw ContractException if the contract couldn't be ensured
*/
int KDB::ensure (const KeySet & contract, Key & parentKey)
{
// have to ksDup because contract is consumed and ksDel()ed by kdbEnsure
int ret = ckdb::kdbEnsure (handle, ckdb::ksDup (contract.getKeySet ()), parentKey.getKey ());

This comment has been minimized.

Copy link
@sanssecours

sanssecours Mar 31, 2019

Member

I think you can replace

ckdb::ksDup (contract.getKeySet ())

with the shorter

contract.dup ()

here.

This comment has been minimized.

Copy link
@kodebach

kodebach Mar 31, 2019

Author Contributor

No that won't work, because that will cause a double free, because the C++ class KeySet will call ksDel() in the destructor.

if (ret == -1)
{
throw KDBException (parentKey);
}
if (ret == 1)
{
throw ContractException (parentKey);
}
return ret;
}


} // end of namespace kdb

#endif
@@ -60,10 +60,30 @@ class KDBException : public Exception
return m_str.c_str ();
}

private:
protected:
Key m_key;
mutable std::string m_str;

This comment has been minimized.

Copy link
@markus2330

markus2330 Mar 30, 2019

Contributor

Could be private?

};

class ContractException : public KDBException
{
public:
explicit ContractException (Key key) : KDBException (key)
{
}

~ContractException () noexcept override = default;

const char * what () const noexcept override
{
if (!m_key)
{
return "Malformed contract";
}
return KDBException::what ();
}
};

} // namespace kdb

#endif
@@ -1339,3 +1339,9 @@ severity:error
ingroup:plugin
module:specload
macro:SPECLOAD

number:213
description:the contract was malformed
severity:error
ingroup:kdb
macro:MALFORMED_CONTRACT
@@ -110,6 +110,7 @@ int kdbGet(KDB *handle, KeySet *returned,
int kdbSet(KDB *handle, KeySet *returned,
Key *parentKey);

int kdbEnsure (KDB * handle, KeySet * contract, Key * parentKey);


/**************************************
@@ -202,7 +202,4 @@






#endif
@@ -30,6 +30,7 @@
POSITION(GETRESOLVER) \
POSITION(PREGETSTORAGE) \
POSITION(GETSTORAGE) \
POSITION(PROCGETSTORAGE) \
POSITION(POSTGETSTORAGE) \
POSITION(SETRESOLVER) \
POSITION(POSTGETCLEANUP) \
@@ -323,9 +323,6 @@ struct _KDB

ElektraIoInterface * ioBinding; /*!< binding for asynchronous I/O operations.*/

Plugin * notificationPlugin; /*!< reference to global plugin for notifications.*/
ElektraNotificationCallbackContext * notificationCallbackContext; /*!< reference to context for notification callbacks.*/

KeySet * global; /*!< This keyset can be used by plugins to pass data through
the KDB and communicate with other plugins. Plugins shall clean
up their parts of the global keyset, which they do not need any more.*/
@@ -519,6 +516,7 @@ int elektraProcessPlugin (Key * cur, int * pluginNumber, char ** pluginName, cha
int elektraProcessPlugins (Plugin ** plugins, KeySet * modules, KeySet * referencePlugins, KeySet * config, KeySet * systemConfig,
KeySet * global, Key * errorKey);
size_t elektraPluginGetFunction (Plugin * plugin, const char * name);
Plugin * elektraPluginFindGlobal (KDB * handle, const char * pluginName);

Plugin * elektraPluginMissing (void);
Plugin * elektraPluginVersion (void);
@@ -89,7 +89,6 @@ int keyRel2 (const Key * k1, const Key * k2, KeyRelType which);
Key * keyAsCascading (const Key * key);
int keyGetLevelsBelow (const Key * k1, const Key * k2);


#ifdef __cplusplus
}
}
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.