-
Notifications
You must be signed in to change notification settings - Fork 123
Help message not printed when high level API with code generation is used #3998
Comments
First of all, only You didn't mount the specification (there should be libelektra/src/tools/kdb/gen/highlevel/highlevel.cpp Lines 213 to 230 in 71ecdaf
I investigated this a bit and it turns out this is a bug in the opts library. Specifically that |
Thanks for your comments! I'll investigate further. |
I created #3999 for the issue of missing command line options in the help message. @kodebach: I'd appreciate your opinion on these 2 topics: Mounting before executing application
Behavior of help message depends on mount statusThere are 2 mount conditions to consider:
That leads to 3 possible combinations:
@kodebach Do you agree that this case should never happen, because the application should simply fail, if SFM=no?
@kodebach Do you agree that this case should never happen, because the application should simply fail, if SFM=no?
@kodebach Do you agree that this would be the only legal case? |
In theory yes, however, currently the code for creating mountpoints is written in C++, so calling it from C is not as easy. Some of the mounting code needs to change for #3693. Probably we should rewrite it in pure C.
The One thing you have to keep in mind is that the mounting only has to be done during installation. So it would probably not make that much sense to build it directly into the main executable. However, a basic check whether the mounting has happend could be put into the executable. Then we could at least show an error message, if the specification wasn't mounted.
In general, the idea was that In the case of a missing specification (SFM=no or SME=no), we could print an additional message stating that the specification was not found (before/after the help message). If |
Thanks for your comment, I'll continue work on this issue at a later point in time, probably after fixing #3999. |
@kodebach Thanks, I agree with everything you wrote! Suggested fixI suggest to detect the state of SFM and SME within libelektra/src/libs/highlevel/elektra.c Lines 119 to 121 in 5702ce0
If SFM=false or SME=false, we can return NULL and set a a sensible error message within the But: How can we detect the state of SFM and SME? SFMI have diff'ed
Therefore, would it suffice to check if E.g. SMEDo you have a suggestion on how to check for SME? Can any of them be used as an indicator for SME? Maybe
E.g. for redshift:
|
@markus2330 I noticed I never mentioned you in this issue (as you've asked me to). Sorry, I'm doing it now. |
It is better than nothing, but it doesn't really tell you that the spec file was mounted. It could be that just the parent key was set. Checking You already noticed this for SME, but it works for SFM too. Just check that
As you noticed, you can use For now, I think the simple checks above are enough. But... The above checks don't really validate that the correct spec was mounted (just that something is mounted at I don't think there is a 100% foolproof way to check SFM and SME, but we could do a bit better than above. To give a bit more certainty whether the correct spec was mounted, we could look for a token value. The code-generator could just add something like this to the spec it generates (i.e. the spec that should be mounted): []
mountpoint = some_file.ext ; already there
token = some_random_value_or_maybe_just_hash_of_spec ; new
; rest of spec ... The For SME this would be bit more complicated. We could create a plugin that looks for the (*) Technically this is not a 100% correct check, but it works most of the time (namely when |
Thanks, that's helpful. I believe it is sensible to implement the simple checks now and something more elaborate later, sometime after #3693 is solved. @markus2330 Do you agree? |
I like the idea with the token, it is a sensible choice for code generation as you can easily generate unique tokens and the check is a simple string comparison (if the same token is compiled in the application, is present in spec: and is used for spec-mount). I think, without correct token, we should fail at application startup, and not only for the --help message. |
Why not simply let spec-mount copy the token to the mountpoint definition, e.g. |
Yes, I would add a new return code for
Yes, that should work too and might not even require any changes to spec-mount. |
Thanks for your comments! This week I have implemented a version that:
I will extend this version according to the decisions below.. I propose to postpone a new return code until Decisions from call @markus2330 and @qwepoizt 09th Sep 2021:
|
Where will the actual token be? |
It is not only a program language barrier problem but currently also a permission problem: mounting without #1074 requires root. |
Good point, thanks! You're right, it will also have to be part of the contract. Then the keys could be:
|
If generated code always enables the check, I don't think you need the |
Good point, thanks. I'll look at it in more detail when I start implementing it! While working on redshift's automake configuration, looking at https://github.com/kodebach/lcdproc/blob/3e2b9d3f5cade3bbe21fdb5a9ea1c9ffc1c994fa/server/Makefile.am and the libelektra/src/libs/highlevel/elektra.c Lines 327 to 378 in e9d0afa
I guess, I need to schedule an appointment with my optican 😆 . That means:
|
@markus2330 @kodebach I had further insights that complicate this issue. I think we'll need to make further decisions! I'll use redshift as an example to make the following easier to understand. Insights
This raises several points for discussion. I'll think about them and appreciate your thoughts:
|
Yes, please remove 👍
Where did you see this? This is probably outdated docu or a non-working script. The specload plugin was an approach to solve the SFM/SME problems but unfortunately it did not work well, e.g., it makes the application binaries too big.
Yes, as specload is not mandatory and in its current state not even recommendable.
If the token mechanism works well and we don't find solutions for specload we will remove specload.
These changes are allowed on purpose (they are harmless). But your question is probably something else: Fixing the problems of specload is probably much harder (e.g. finding an encoding that doesn't bloat the binaries so much) than implementing the token mechanism. If you think specload is the way to go, you are free to fix the problems and use it for redshift.
This wouldn't prevent from installing wrong versions of the specification. |
The
I think the binary size was an issue mainly for embedded systems. But there are other issues as well, related to the other goals (allow only "safe" modifications).
The way I understand it, the issue was that on some embedded systems there is limited amount of storage for executable data, but more additional (often slower) storage for non-executable data. If the whole thing is a single file, everything has to be in one type of storage. In these cases I don't think it will ever really make sense to embed the config, without some other clear benefit.
Yes, I too think, However, a new optional plugin to enhance the token mechanism might be something to think about. This new plugin would generate the hash/token on-the-fly and replace the stored value during |
Thanks for your input! I thought some more about this and came up with a list of planned changes (see below). @markus2330 Are you fine with this plan? I tried to keep it simple without over-engineering, but maybe it can be simplified? If you're fine with it, please let me know and I'll start working on it! Planned changesToken mechanism
Checking SFM and SME
Removing features
Answers on your questions/comments
|
I am planning to use https://github.com/CTrabant/teeny-sha1 , because:
|
See #4032 for further discussion. I am surprised that the binary size barely increased (probably because the spec is much smaller). Furthermore, it worked for me without problems and has the big advantage that the spec: automatically updates with any updates of the binary. But it does not really matter for the token implementation, also with specload inconsistency can arise (wrong binary mounted, spec-mount not executed), so the token solution will be required in any case.
full ack
Please also look into specload and see if it is somehow maintainable and does a good job. Ok, I did not look into alternatives, though. sh256 would probably a bit more future-safe, it sounds reasonable that people at some point will try to trick applications to use a wrong specification. Btw. a plugin that implements a check if values or meta-data were modified without using Elektra would be very nice. Maybe you can make the implementation in a way, that implementing such a plugin gets easy (which would be the case if you implement it in a function of the code-gen-support library, as this library could also be used in the plugin). |
Decisions from Elektra meeting 13th Sep 2021:
|
Good point, thanks. I'll use https://github.com/amosnier/sha-2 instead, which is also short and license compatible. |
amosnier/sha-2 looks easier to use anyway, since it has a streaming API. The other library would have required creating one single, big buffer for all the data you want to hash. Hashing a complete specification would have meant creating a complete duplicate of it just to calculate the hash. |
@markus2330 Which library are you referring to? All of the |
You could simply include the int elektraSha256Hash (uint8_t hash[32], KeySet * input) |
@markus2330 I have an update: This is progressing well! Done
Current issueCurrently, I am seeing some problems with arrays:
My first idea was to ignore all metadata on array items. I.e. keys whose basenames start with @markus2330 What do you think about this? Is there a better approach? |
There is a similar functionality with I think they would not be copied if you only work on |
Yes, the |
Actually, the algorithm should ignore any keys that are not in the spec namespace. I'll create a small test to further debug this! |
@kodebach I'd like to fix this myself as part of my thesis, but beforehand I'd appreciate your assessment:
Can you take a look at this? Have I configured something wrong or is this a bug/regression?
Steps to Reproduce the Problem
Execute the steps below which follow the tutorial High-level API (with code-generation).
Note: The steps below use a different signature for
loadConfiguration()
than the tutorial, because the tutorial is outdated (see https://github.com/ElektraInitiative/libelektra/pull/3997/files).Create file test.ini with content:
Execute
kdb gen -F ni=test.ini highlevel "/sw/example/myapp/#0/current" conf
Create file myapp.c with content:
cc myapp.c conf.c `pkg-config --cflags --libs elektra-codegen` -I. -o myapp -Wl,-rpath `pkg-config --variable=libdir elektra-codegen`
--help
./myapp --help
-h
./myapp -h
Expected Result
The help message generated by code generator should be printed including information about the supported command line argument
--temp-day
.Actual Result
Nothing is printed.
System Information
The text was updated successfully, but these errors were encountered: