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
CFE-2788: Added __main__ bundles with special semantics #3118
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3118 +/- ##
==========================================
- Coverage 61.96% 61.95% -0.02%
==========================================
Files 210 210
Lines 45921 45978 +57
==========================================
+ Hits 28455 28485 +30
- Misses 17466 17493 +27
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think this is a great idea. We just need to be careful. As always. :)
libutils/sequence.c
Outdated
} | ||
s->data[to] = s->data[from]; | ||
++from; | ||
++to; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer else
here instead of continue
, but YMMV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I (obviously) preferred the continue
, but maybe I'll change it. Just because it's you ;)
libpromises/loading.c
Outdated
@@ -253,6 +255,44 @@ static void ShowContext(EvalContext *ctx) | |||
SeqDestroy(soft_contexts); | |||
} | |||
|
|||
static void RenameMainBundle(EvalContext *ctx, GenericAgentConfig *config, Policy *policy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config
seems to be unused here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
libpromises/loading.c
Outdated
{ | ||
const char *const path = bundle->source_path; | ||
char *abspath = GetAbsolutePath(path); | ||
if (StringSafeEqual(abspath, entry_point)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to worry about symlinks here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I thought about this too, I'll see if we have a realpath function.
libpromises/loading.c
Outdated
{ | ||
Log(LOG_LEVEL_VERBOSE, "Redefining __main__ bundle from file %s to be main", abspath); | ||
free(bundle->name); | ||
name = bundle->name = xstrdup("main"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. Why? This is ugly and there's no need to assign to name
here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll have to be more specific, what are you saying "Why?" to?
Assigning to name isn't strictly necessary.
Do you dislike the renaming to "main"? I preferred this over other more complicated solutions. It seems to be pretty backwards compatible, and is easy to explain the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the double-assignment, I only consider it okay when initializing variables. The name main
is fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, in that case, fixed! :)
libpromises/loading.c
Outdated
Log(LOG_LEVEL_VERBOSE, "Redefining __main__ bundle from file %s to be main", abspath); | ||
free(bundle->name); | ||
name = bundle->name = xstrdup("main"); | ||
main_counter += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a global variable then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should be a global variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, there should only be one main
bundle across all the policy files loaded, right? Or is it okay if there are multiple ones in different files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, makes sense. I removed it though, because we should already have checks for this.
libpromises/loading.c
Outdated
{ | ||
Log(LOG_LEVEL_VERBOSE, "Dropping __main__ bundle from file %s (entry point: %s)", abspath, entry_point); | ||
removed = true; | ||
SeqSet(bundles, i, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the bundle be properly destroyed (deallocated) here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SeqSet calls destroy function, so no, that would be a double free.
1aa7067
to
7324cf3
Compare
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
If the bundle is defined in the entry policy it will be defined as main. If the bundle is defined elsewhere, it will be removed. This makes it easy to make importable library policy which can also be executed directly. Changelog: Commit Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
@vpodzime I addressed all your comments, added a realpath function for symlinks and got rid of the unnecessary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now, thanks! Let's see if the concerns about realpath()
from its man page are just rumors.
Log(LOG_LEVEL_VERBOSE, | ||
"Redefining __main__ bundle from file %s to be main", | ||
abspath); | ||
strncpy(bundle->name, "main", 4+1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too bad one cannot write ++4
😉
Did some more manual testing. Seems to work as expected:
|
The failures are unrelated. Merging. |
Added follow-up tasks: |
This has been cherry-picked in #3137 |
Example usage: