$darkmode
Elektra 0.11.0
Ensure

Problem

Applications want to ensure that some functionality (hooks) is present in Elektra.

Constraints

Assumptions

Considered Alternatives

Decision

Integrate kdbEnsure in kdbOpen(Key *errorKey, KeySet *contract) but only allow hooks.

Rationale

Implications

elektraNotificationOpen will be renamed and only return a contract KeySet:

KeySet * errorKey = keyNew ("/", KEY_END);
KeySet * contract = ksNew (0, KS_END);
elektraNotificationContract (contract, iobinding, errorKey);

The same for gopts:

elektraGOptsContract (contract, argc, argv, environ, errorKey);

Finally, we create KDB with the contracts we got before:

KDB * kdb = kdbOpen (contract, parentKey);

Opening KDB will fail if any of the contracts cannot be ensured.

As the contract gets copied, at any point after kdbOpen the contract can be safely deleted:

1 ksDel (contract);

The cleanup of the global plugins happens within:

kdbClose (kdb, errorKey);

It is safe to use the contract KeySet also for kdbGet and kdbSet invocations. Contract KeySets only contain Keys below system:/elektra/contract. Therefore, normal KeySets should not interfere.

Related Decisions

Notes