Conversation
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
b7d8916 to
33ee80a
Compare
| VarRefDestroy(ref); | ||
| } | ||
|
|
||
| static PromiseResult KeepAgentPromise(EvalContext *ctx, const Promise *pp, ARG_UNUSED void *param) |
f98bd05 to
36fa38f
Compare
Signed-off-by: Victor Moene <victor.moene@northern.tech>
36fa38f to
0f805bb
Compare
larsewi
left a comment
There was a problem hiding this comment.
Please do a review with Claude. For me it found a few things that seem plausible:
- A remote
copy_fromin athenbundle crashes cf-reactor - State builds up across repeated runs of the same bundle
- The
EvalAbortedbranch is dead code
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Promises are skipped to prevent running them several times. However, on event, we want to run them every single time: - we clear the promise lock cache - we set the default if_elapsed time for bundles run from an events promise to be 0, so it doesn't skip the promises. Fixed also connection cache and custom promise prologue and epilogue. Clear function cache before "then" bundle run Signed-off-by: Victor Moene <victor.moene@northern.tech>
- No need for map anymore, since watcher keeps track of the promise - No need to keep key as variable anymore, since we do not use a map - No need to run bundle inside watcher.c - No risk of running a bundle from a wrong key between policy reads Signed-off-by: Victor Moene <victor.moene@northern.tech>
Signed-off-by: Victor Moene <victor.moene@northern.tech>
0f805bb to
1bb39a3
Compare
The issue is that classes and variables declared once will stay declared until the next policy reload. So a class can stay defined between runs, when the state it checks changed. Instead, the state of all vars and classes is saved in a snapshot after a policy reload, and before every "then" bundle run, we restore the snapshort, and the defined classes and vars of the ran bundles will stay until the next event triggered run. Signed-off-by: Victor Moene <victor.moene@northern.tech>
Instead of destroying all watchers, it now keeps the state, such that, even if an event happens during policy reload, it will get detected by comparing the previous state. Signed-off-by: Victor Moene <victor.moene@northern.tech>
1bb39a3 to
5a8c477
Compare
| * removes the ones defined by the previous 'then' bundle runs, defines again | ||
| * the ones they cancelled and sets back the values they changed. Then | ||
| * reloads the persistent classes that have not expired. */ | ||
| static void ContextSnapshotRestore(EvalContext *ctx) |
craigcomstock
left a comment
There was a problem hiding this comment.
looks good generally
| "meta", | ||
| "vars", | ||
| "defaults", | ||
| "classes", /* Maelstrom order 2 */ |
There was a problem hiding this comment.
what is this comment? maelstrom order 2?
There was a problem hiding this comment.
ah, I see, existing code, copied over... git log can tell us.
There was a problem hiding this comment.
funny, this array has been moved BEFORE! from libpromises/constants.c to cf-agent/cf-agent.c: 43035ad
and then that was reverted: 48fe18f
constants.c is rather old, was renamed from src/constants.c to libpromises/constants.c here: 11e2c21#diff-efd2f7f382b829b3e9838d3c76e8221d965eee910658777d3ca9e777c5b4d4cb (Jan 4, 2013)
I couldn't find a commit that added this fun comment. Also didn't find it in https://ftp.gnu.org/gnu/cfengine/ (1.4.0 or 2.0.6 (the oldest and newest sources there)).
| * AGENT_TYPESEQUENCE order, keeping each one with KeepAgentPromise()). It is | ||
| * kept separate from cf-agent.c so that other components (e.g. cf-reactor, | ||
| * running the bundle named in an events promise's "then") can run a bundle | ||
| * the same way cf-agent does, without linking cf-agent's main(). */ |
There was a problem hiding this comment.
This feels like a fairly disruptive change. I wonder if you could instead factor out cf-agent's main() and friends from cf-agent.c say into a cf-agent-main.c and that might be a smaller change that impacts less functional code.
There was a problem hiding this comment.
I asked claude to refactor this way and the result looks about as invasive: https://github.com/craigcomstock/core/pull/new/ent-14463-part-3-alt-refactor, maybe take a look and see what you think.
|
|
||
| const Bundle *bundle = NULL; | ||
| if (bundle_name != NULL) | ||
| const Bundle *bp = NULL; |
There was a problem hiding this comment.
why the change from bundle to less obvious bp? is this short for something new?
There was a problem hiding this comment.
were you trying to convey "bundle pointer" like "pp" is "promise pointer"?
|
|
||
| if (EvalAborted(ctx)) | ||
| { | ||
| Log(LOG_LEVEL_ERR, "Eval aborted"); |
There was a problem hiding this comment.
what does "eval aborted" mean? might be nice to explaing more about this.
| EvalContextStackPushBundleSectionFrame(ctx, pp->parent_section); | ||
| ExpandPromise(ctx, pp, KeepEventsPromiseOnEvent, &event); | ||
| EvalContextStackPopFrame(ctx); | ||
| EvalContextStackPopFrame(ctx); |
There was a problem hiding this comment.
might be nice to add a comment after each about which stack frame you think you are popping: bundle section and then bundle I assume.
| const Watcher *w = MapGet(watchers_by_key, key); | ||
|
|
||
| if (bundle == NULL) | ||
| if (w == NULL) |
There was a problem hiding this comment.
might as well call this watcher instead of w.
| } | ||
| VariableTableIteratorDestroy(snapshot_iter); | ||
| } | ||
|
|
There was a problem hiding this comment.
all of this snapshot code feels a bit generic. I wonder if most of it could live in a more shared location like libpromises?
| @@ -0,0 +1,602 @@ | |||
| # Makefile.in generated by automake 1.16.5 from Makefile.am. | |||
There was a problem hiding this comment.
asan makefile should not be committed.
| EvalContextSetBundleArgs(ctx, NULL); | ||
| EndBundleBanner(bp); | ||
|
|
||
| if (EvalAborted(ctx)) |
There was a problem hiding this comment.
Maybe this should have not been added to begin with in the previous commit?
| static bool ifelapsed_pushed = false; | ||
| static int pushed_ifelapsed = 0; |
There was a problem hiding this comment.
We should really try to avoid these static variables. Global variables are evil. And making them file private does not help that much. What if you return then from the push function and pass them to the pop function? Also the wording push and pop makes me think it is a stack, which this is not.
How about
int old_value = OverrideIfelapsed(0);
/* Do your thing */
RestoreIfelapsed(old_value);
No description provided.