$darkmode
| Elektra 0.11.0
    | 
This plugin spawns a new process with a user-defined executable and delegates all operations to the new process.
Set the config key executable and the arrays args/#, env/# to the path of an executable, the arguments that shall be passed and the environment variables to be set.
During elektraStdprocioOpen the plugin will collect the args/# and env/# values into two arrays argv and envp. Additionally, the array copyenv/# is read as a list of environment variables. Each variable will be looked up via getenv and then added to envp.
The plugin then forks a new process and the child calls execve with the path from app as well as argv andenvp. The child process is expected to listen to stdin and write to stdout according to the protocol described below.
If communication can be established, the child process will be kept running until elektraStdprocioClose.
The entire protocol is text-based (apart from binary key values) and request-response-based, and happens over stdin/stdout. The parent process sends request to the child process. The child then processes the request and sends a response back.
To encode keysets and keys we use the format of the dump plugin. It is important to note that the dump plugin is instructed to write the full keynames (normally it removes the parent prefix). There is, however, an exception during initialization, which is described in the appropriate section. The child process may also delegate directly to the dump plugin, or reimplement the encoding.
The communications protocol used by the plugin has 3 phases:
Note: In the sections below we use the following format to describe messages:
Parent > ChildHELLO WORLD[users](user){ok|error}This denotes a message sent from parent to child, containing
- the literal text
HELLO WORLD- followed by a newline
- followed by a keyset called
users- followed by a newline
- followed by dynamic text called
user- followed by either the literal text
okor the literal texterrorThe names
usersanduserdon't actually appear in the message. They are only used as a reference for the descriptions of the message.The actual message sent could look like this:
HELLO WORLDkdbOpen 2$key string 3 5joe12345$endappleseed
The parent writes the protocol header to stdin of the child.
The child must respond with an acknowledgement, followed by a contract keyset.
Here (name) is the module name the child uses. This will be used to replace process in the contract of the plugin. The [contract] keyset must contain the infos keys, which will be used replace the ones at the top of this README and the ones in process.c. It must also contain exports/_ keys for every operation that is implemented by the child. All keys in [contract] should be below system:/elektra/modules/process. The parent will rename these keys appropriately.
A child that implements all operations should include these keys (in addition to the relevant infos keys):
After this initial handshake, the child should simply wait for further requests from the parent.
Note: Under normal circumstances this handshake will always be followed by an
openrequest immediately.
When the parent needs the child to process an operation (open, get, ...), it will send a request like this:
First we send the opname (one of open, get, set or close) of the operation that shall be performed by the child. The keyset [parent] always consists of a single key, namely the parentKey (or errorKey) that was passed to the plugin. Finally, [data] is the keyset that was passed to the plugin. The [data] keyset is not present in open and close operations, since those don't receive a KeySet in the C API. However, in the open operation [data] is replaced [config] which is the KeySet returned by elektraPluginGetConfig in the C API. This is needed, because the child process cannot request the config keyset otherwise.
The child should then perform the requested operation and respond with
Here (result) is one of success, noupdate and error, which correspond to ELEKTRA_PLUGIN_STATUS_SUCCESS, ELEKTRA_PLUGIN_STATUS_NO_UPDATE and ELEKTRA_PLUGIN_STATUS_ERROR respectively. The keysets [parent] and [returned] are the modified versions of the one sent by the parent.
When the parent no longer needs the child process, it will send a final termination request.
The child process should now exit (and thereby close its ends of the stdin/stdout pipes).
Note: Under normal circumstances this only happens, when plugin is being closed, i.e. during a
elektraPluginClosecall for aprocessinstance.
If an unexpected error occurs on either side of the protocol, the connection should be terminated and the child process shall exit.
Note: The mount line of the snippet above can be simplified by using the
mount-javahelper:sudo kdb mount-java config.file user:/tests/process dump java:org.libelektra.plugin.WhitelistPlugin
error and commit functions are currently not supported. Therefore, implementing a resolver is not supported.checkconf) is currently not supported.process can only be used for plugins in the postgetstorage or presetstorage positions.