Skip to content

CFE-3658: Refactor augments loading code - #6484

Open
victormlg wants to merge 7 commits into
cfengine:masterfrom
victormlg:augments-refactor
Open

victormlg wants to merge 7 commits into
cfengine:masterfrom
victormlg:augments-refactor

Conversation

@victormlg

Copy link
Copy Markdown
Contributor
  • Moved augments loading code to its own file (augments.c)
  • Split LoadAugmentsData into ReadAugment.* helper functions
  • Split ReadAugment.* functions into helper functions
  • Moved shared code between augments.c and cmdb.c into json_data.c
  • Fixed crash on non-array class expressions and CanSetClass() leak

@craigcomstock craigcomstock left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, didn't have time to review the code. I was only able to review the commit messages/content (why you are making these changes) and whether you might add a test that exposes the crash/leak.

Comment thread libpromises/augments.c Resolved
Comment thread libpromises/augments.c Resolved
Comment thread libpromises/augments.c Resolved
Comment thread libpromises/host_data.c Resolved
Comment thread libpromises/augments.c
Log(LOG_LEVEL_VERBOSE,
"Cannot set class %s:%s from augments, already defined from host-specific data",
ns, class_spec);
(ns != NULL) ? ns : "default", class_spec);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what led you to do the refactoring? Should there be a unit test that exposes the crash? Are there two bugs? a crash and a leak? Or is that describing one issue?

Moved from generic_agent.[ch] to augments.[ch], code unchanged.
First step towards splitting it up and sharing code with cmdb.c.

Ticket: CFE-3658
Signed-off-by: Victor Moene <victor.moene@northern.tech>
LoadAugmentsData() was a single ~500 line function handling all keys inline.
One function per top-level key, mirroring cmdb.c, makes it readable and allows
sharing code with cmdb.c in the following commits.

Ticket: CFE-3658
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Removes duplicated code for installing variables and classes.

Ticket: CFE-3658
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Both files had near-identical copies of these helpers.

Ticket: CFE-3658
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Bug already present on master.

Ticket: CFE-3658
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Bugs already present on master. The leak is only visible with
valgrind/ASan.

Ticket: CFE-3658
Signed-off-by: Victor Moene <victor.moene@northern.tech>
It said "augment inputs". Already present on master.

Ticket: CFE-3658
Signed-off-by: Victor Moene <victor.moene@northern.tech>
@larsewi

larsewi commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Please format the policy files :)

Comment thread libpromises/augments.c
@@ -0,0 +1,783 @@
/*
Copyright 2024 Northern.tech AS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026

Comment thread libpromises/augments.h
@@ -0,0 +1,38 @@
/*
Copyright 2024 Northern.tech AS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2026

Comment thread libpromises/augments.c
@@ -22,6 +22,29 @@
included file COSL.txt.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take out one function at the time. Otherwise the diff will be unreadable.

@larsewi

larsewi commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Wait, I will try something first

@larsewi

larsewi commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

I will re-review with

git show --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change HEAD~<N>

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for refactoring. The diff is unreadable, so I've just went though it quickly. In the future it might be a good idea to break it up a bit more. E.g., extract one function out of the 500 line function, one at the time. Then it's easy for a human to verify that this is what is actually being done.

It's nice that you kept bug fixes out of the refactor commits 🚀 However, these should have a changelog entry.

Comment thread libpromises/augments.c
continue;
}

/* NULL_JSON() above also treats a JSON null as not specified */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit deserves a changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants