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

gopts: Wrong type detected too late #4043

Closed
qwepoizt opened this issue Sep 14, 2021 · 9 comments · Fixed by #4045
Closed

gopts: Wrong type detected too late #4043

qwepoizt opened this issue Sep 14, 2021 · 9 comments · Fixed by #4045
Assignees

Comments

@qwepoizt
Copy link
Contributor

Forked from #4029.

This is "Class 2: wrong type".

Steps to Reproduce the Problem

see #4029

Expected Result

see #4029

Actual Result

see #4029

System Information

see #4029

@qwepoizt qwepoizt changed the title gopts: wrong type detected too late gopts: Wrong type detected too late Sep 14, 2021
@qwepoizt
Copy link
Contributor Author

qwepoizt commented Sep 14, 2021

@kodebach wrote in #4029:

I thought that at least type also does its validation during kdbGet.

It does. But: The opts library seems to not copy the meta-keys from the keys within spec:/ to the keys within proc: .

Once elektraTypeGet() is called, the keys in the KeySet have no meta data.

E.g. for ./myapp --mb notabool using the spec given in #4029:

image

@kodebach Do you remember if the meta-keys are not copied from spec:/ to proc:/ on purpose? Would the fix be to

  1. copy the metadata
  2. or to lookup the metadata from spec:/ within elektraTypeGet() ?

@qwepoizt
Copy link
Contributor Author

(mentioning @markus2330 as discussed.)

@qwepoizt
Copy link
Contributor Author

Addendum:
Because they have no metadata getTypeName(cur) returns NULL and their type is not validated within elektraTypeGet() - these keys are simply skipped:

Key * cur = NULL;
while ((cur = ksNext (returned)))
{
const char * typeName = getTypeName (cur);
if (typeName == NULL)
{
continue;
}

The wrong type is then noticed later, when the exact key is retrieved using the elektraGetMyboolean() function generated by kdb gen, as explained here

@kodebach
Copy link
Member

But: The opts library seems to not copy the meta-keys from the keys within spec:/ to the keys within proc: .

The spec plugin should do that. First all plugins up to and including the getstorage position should run. Then gopts should run (in the procgetstorage global position), then spec should run (postgetstorage global position) and finally all the plugins in postgetstorage position should run.

Can you verify whether gopts, spec and type are executed in this order? If they are, this is probably a bug in the spec plugin.

@qwepoizt
Copy link
Contributor Author

qwepoizt commented Sep 14, 2021

No, the order is gopts, type, spec!

gopts is run in procgetstorage and spec is run in postgetstorage. I'm not sure in which position type is run, but it's call stack shows that it is not executed via the list plugin while gopts and spec are.

Call stacks

gopts

1st call
image
2nd call
image

type

1st call
image
2nd call
image
3rd call
image

spec

1st call
image

@kodebach
Copy link
Member

No, the order is gopts, type, spec!

Well, that will never work... But in that case it also shouldn't work, if you manually edit the config file. spec must always run first, to copy the metadata. This actually quite a severe bug...

I had a quick look at the source of kdbGet() and I'm not 100% sure that this would work, but I think we just need to move these

if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, INIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, MAXONCE) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}
if (elektraGlobalGet (handle, ks, parentKey, POSTGETSTORAGE, DEINIT) == ELEKTRA_PLUGIN_STATUS_ERROR)
{
goto error;
}

immediately after the two calls to splitMergeBackends. So the result should look like this:

// ...

if (/* big condition with POSTGETSTORAGE and PROCGETSTORAGE */)
{
    // other stuff
    splitMergeBackends (split, ks);
    // THE SNIPPET ABOVE
    clearError (parentKey);
    // other stuff
}
else
{
    // other stuff
    splitMergeBackends (split, ks);
    // THE SNIPPET ABOVE
}
keySetName (parentKey, keyName (initialParent));

// SNIPPET REMOVED HERE

if (handle->globalPlugins[POSTGETCACHE][MAXONCE])
// ...

If this doesn't work, I fear you'll have to wait until I've finished #3693

@qwepoizt
Copy link
Contributor Author

Yes, after this change, the order is now gopts, spec, type!

@kodebach Can you please make sure that this is indeed a good fix for the problem and create a PR for it?
Are you the right person for that task?
Unfortunately, I don't know how kdbGet() works and what side-effects such a change could have, so I am quite at a loss here :).

@qwepoizt
Copy link
Contributor Author

@markus2330 I've discovered another problem in kdb.c that might be related #4044.

@kodebach kodebach self-assigned this Sep 14, 2021
@kodebach
Copy link
Member

Yes, I will look into fixing this and #4044. Since #3693 will change a lot of this code anyway, I'd say as long as the change doesn't cause test failures it is good enough for now.

kodebach added a commit to kodebach/libelektra that referenced this issue Sep 14, 2021
@kodebach kodebach mentioned this issue Sep 14, 2021
20 tasks
tucek pushed a commit to tucek/libelektra that referenced this issue Sep 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants