Skip to content

Commit c255477

Browse files
committed
Created ScheduleAgentOperationsTopDown function
Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent 84e2cbd commit c255477

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

cf-agent/cf-agent.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,15 @@ static void AllClassesReport(const EvalContext *ctx)
15591559

15601560
PromiseResult ScheduleAgentOperations(EvalContext *ctx, const Bundle *bp)
15611561
// NB - this function can be called recursively through "methods"
1562+
{
1563+
if (EvalContextGetEvalOption(ctx, EVAL_OPTION_TOP_DOWN_EVALUATION))
1564+
{
1565+
return ScheduleAgentOperationsTopDown(ctx, bp);
1566+
}
1567+
return ScheduleAgentOperationsNormalOrder(ctx, bp);
1568+
}
1569+
1570+
PromiseResult ScheduleAgentOperationsNormalOrder(EvalContext *ctx, const Bundle *bp)
15621571
{
15631572
assert(bp != NULL);
15641573

@@ -1652,6 +1661,61 @@ PromiseResult ScheduleAgentOperations(EvalContext *ctx, const Bundle *bp)
16521661
return result;
16531662
}
16541663

1664+
PromiseResult ScheduleAgentOperationsTopDown(EvalContext *ctx, const Bundle *bp)
1665+
{
1666+
assert(bp != NULL);
1667+
1668+
int save_pr_kept = PR_KEPT;
1669+
int save_pr_repaired = PR_REPAIRED;
1670+
int save_pr_notkept = PR_NOTKEPT;
1671+
struct timespec start = BeginMeasure();
1672+
1673+
if (PROCESSREFRESH == NULL || (PROCESSREFRESH && IsRegexItemIn(ctx, PROCESSREFRESH, bp->name)))
1674+
{
1675+
ClearProcessTable();
1676+
}
1677+
1678+
// maybe 3 passes?
1679+
PromiseResult result = PROMISE_RESULT_SKIPPED;
1680+
const size_t sections = SeqLength(bp->all_sections);
1681+
EvalContextSetPass(ctx, 1);
1682+
for (size_t i = 0; i < sections; ++i)
1683+
{
1684+
BundleSection *section = SeqAt(bp->all_sections, i);
1685+
1686+
if (!section || SeqLength(section->promises) == 0)
1687+
{
1688+
continue;
1689+
}
1690+
1691+
// NewTypeContext(section->promise_type);
1692+
1693+
// SpecialTypeBanner(section->promise_type, 1);
1694+
EvalContextStackPushBundleSectionFrame(ctx, section);
1695+
1696+
const size_t promises = SeqLength(section->promises);
1697+
for (size_t ppi = 0; ppi < promises; ppi++)
1698+
{
1699+
Promise *pp = SeqAt(section->promises, ppi);
1700+
1701+
1702+
PromiseResult promise_result = ExpandPromise(ctx, pp, KeepAgentPromise, NULL);
1703+
result = PromiseResultUpdate(result, promise_result);
1704+
1705+
if (EvalAborted(ctx) || BundleAbort(ctx))
1706+
{
1707+
EvalContextStackPopFrame(ctx);
1708+
NoteBundleCompliance(bp, save_pr_kept, save_pr_repaired, save_pr_notkept, start);
1709+
return result;
1710+
}
1711+
}
1712+
EvalContextStackPopFrame(ctx);
1713+
}
1714+
1715+
NoteBundleCompliance(bp, save_pr_kept, save_pr_repaired, save_pr_notkept, start);
1716+
return result;
1717+
}
1718+
16551719
/*********************************************************************/
16561720

16571721
#ifdef __MINGW32__

libpromises/policy.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ static bool PolicyCheckBundle(const Bundle *bundle, Seq *errors)
727727

728728
success &= PolicyCheckBundleSections(bundle->sections, errors);
729729
success &= PolicyCheckBundleSections(bundle->custom_sections, errors);
730+
success &= PolicyCheckBundleSections(bundle->all_sections, errors);
730731

731732
return success;
732733
}
@@ -1322,6 +1323,7 @@ Bundle *PolicyAppendBundle(Policy *policy,
13221323
bundle->source_path = SafeStringDuplicate(source_path);
13231324
bundle->sections = SeqNew(10, BundleSectionDestroy);
13241325
bundle->custom_sections = SeqNew(10, BundleSectionDestroy);
1326+
bundle->all_sections = SeqNew(10, BundleSectionDestroy);
13251327

13261328
return bundle;
13271329
}
@@ -1427,6 +1429,7 @@ BundleSection *BundleAppendSection(Bundle *bundle, const char *promise_type)
14271429
{
14281430
SeqAppend(bundle->custom_sections, section);
14291431
}
1432+
SeqAppend(bundle->all_sections, section);
14301433

14311434
return section;
14321435
}
@@ -1479,6 +1482,7 @@ static void BundleDestroy(Bundle *bundle)
14791482
RlistDestroy(bundle->args);
14801483
SeqDestroy(bundle->sections);
14811484
SeqDestroy(bundle->custom_sections);
1485+
SeqDestroy(bundle->all_sections);
14821486

14831487
free(bundle);
14841488
}

libpromises/policy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct Bundle_
7979

8080
Seq *sections;
8181
Seq *custom_sections;
82+
Seq *all_sections; // kinda wasting space?
8283

8384
char *source_path;
8485
SourceOffset offset;

libpromises/prototypes3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void yyerror(const char *s);
4444
/* agent.c */
4545

4646
PromiseResult ScheduleAgentOperations(EvalContext *ctx, const Bundle *bp);
47+
PromiseResult ScheduleAgentOperationsNormalOrder(EvalContext *ctx, const Bundle *bp);
48+
PromiseResult ScheduleAgentOperationsTopDown(EvalContext *ctx, const Bundle *bp);
4749

4850
/* Only for agent.c */
4951

0 commit comments

Comments
 (0)