Skip to content

Fixed duplicate log_* entries from action bodies (CFE-85)#6232

Open
nickanderson wants to merge 1 commit into
cfengine:masterfrom
nickanderson:CFE-85/master
Open

Fixed duplicate log_* entries from action bodies (CFE-85)#6232
nickanderson wants to merge 1 commit into
cfengine:masterfrom
nickanderson:CFE-85/master

Conversation

@nickanderson

Copy link
Copy Markdown
Member

Summary

  • Fixed DoSummarizeTransaction producing duplicate entries in log_kept/log_repaired/log_failed files when a promise is evaluated multiple times per run (once per pass, once per sub-attribute check like create vs perms)
  • Deduplicates by recording each promise's PromiseID in a StringSet on the EvalContext; subsequent calls for the same promise are skipped
  • Gated on at least one log_* target being configured, so promises without action bodies pay zero cost

Test plan

  • Unit test test_log_action_dedupe in eval_context_test.c: drives cfPS() twice for the same promise and asserts only one line is written; also verifies distinct promises (different bundle/file/line) targeting the same path are NOT suppressed
  • Acceptance test cfe_85.cf: two promisers with create => "true" and an action body; asserts exactly 2 lines in the repaired log (one per promiser, no duplicates)
  • Existing unit and acceptance tests pass (no regressions)

Ticket: CFE-85

Comment thread libpromises/eval_context.c Fixed
Comment thread libpromises/eval_context.c Fixed
Comment thread libpromises/eval_context.c Fixed
Comment thread libpromises/eval_context.c Fixed
Comment thread libpromises/eval_context.c Fixed
}

char key[CF_BUFSIZE];
xsnprintf(key, sizeof(key), "%s:%s", PromiseID(pp), pp->promiser);
A single promise could produce multiple identical entries in the log_kept,
log_repaired, or log_failed files configured via an action body.  This
happened because DoSummarizeTransaction is called once per evaluation pass
and once per sub-attribute check (e.g. create then perms), each writing to
the log file independently.

Fix by recording a composite key (PromiseID + expanded promiser) in a
StringSet on the EvalContext the first time a promise is logged, and
skipping subsequent calls for the same key.  PromiseID alone would falsely
suppress a parameterized bundle called with different arguments (same source
line, different expanded promiser); the expanded promiser alone would
suppress distinct promises in different bundles targeting the same path.
The composite key handles both cases.

The dedup is gated on at least one log_* target being configured, so
promises without action bodies pay no cost.

Ticket: CFE-85
Changelog: Title
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.

2 participants