Skip to content

Commit 543b815

Browse files
committed
Added evaluation_order option in body file control
Changelog: Title Ticket: CFE-4598 Signed-off-by: Victor Moene <[email protected]>
1 parent acd5705 commit 543b815

19 files changed

+65
-29
lines changed

cf-agent/cf-agent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ static void AllClassesReport(const EvalContext *ctx)
15791579
PromiseResult ScheduleAgentOperations(EvalContext *ctx, const Bundle *bp)
15801580
// NB - this function can be called recursively through "methods"
15811581
{
1582-
if (EvalContextIsClassicOrder(ctx))
1582+
if (EvalContextIsClassicOrder(ctx, bp))
15831583
{
15841584
return ScheduleAgentOperationsNormalOrder(ctx, bp);
15851585
}

cf-agent/files_editline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Bundle *MakeTemporaryBundleFromTemplate(EvalContext *ctx, Policy *policy, const
182182
char bundlename[CF_MAXVARSIZE];
183183
snprintf(bundlename, CF_MAXVARSIZE, "temp_cf_bundle_%s", CanonifyName(a->edit_template));
184184

185-
bp = PolicyAppendBundle(policy, "default", bundlename, "edit_line", NULL, NULL);
185+
bp = PolicyAppendBundle(policy, "default", bundlename, "edit_line", NULL, NULL, EVAL_ORDER_UNDEFINED);
186186
}
187187
assert(bp);
188188

cf-monitord/env_monitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void MonitorStartServer(EvalContext *ctx, const Policy *policy)
272272
Policy *monitor_cfengine_policy = PolicyNew();
273273
Promise *pp = NULL;
274274
{
275-
Bundle *bp = PolicyAppendBundle(monitor_cfengine_policy, NamespaceDefault(), "monitor_cfengine_bundle", "agent", NULL, NULL);
275+
Bundle *bp = PolicyAppendBundle(monitor_cfengine_policy, NamespaceDefault(), "monitor_cfengine_bundle", "agent", NULL, NULL, EVAL_ORDER_UNDEFINED);
276276
BundleSection *sp = BundleAppendSection(bp, "monitor_cfengine");
277277

278278
pp = BundleSectionAppendPromise(sp, "the monitor daemon", (Rval) { NULL, RVAL_TYPE_NOPROMISEE }, NULL, NULL);

cf-monitord/history.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ void HistoryUpdate(EvalContext *ctx, const Averages *const newvals)
400400
Policy *history_db_policy = PolicyNew();
401401
Promise *pp = NULL;
402402
{
403-
Bundle *bp = PolicyAppendBundle(history_db_policy, NamespaceDefault(), "history_db_bundle", "agent", NULL, NULL);
403+
Bundle *bp = PolicyAppendBundle(history_db_policy, NamespaceDefault(), "history_db_bundle", "agent", NULL, NULL, EVAL_ORDER_UNDEFINED);
404404
BundleSection *sp = BundleAppendSection(bp, "history_db");
405405

406406
pp = BundleSectionAppendPromise(sp, "the long term memory", (Rval) { NULL, RVAL_TYPE_NOPROMISEE }, NULL, NULL);

cf-serverd/cf-serverd-functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static CfLock AcquireServerLock(EvalContext *ctx,
543543
{
544544
Bundle *bp = PolicyAppendBundle(server_policy, NamespaceDefault(),
545545
"server_cfengine_bundle", "agent",
546-
NULL, NULL);
546+
NULL, NULL, EVAL_ORDER_UNDEFINED);
547547
BundleSection *sp = BundleAppendSection(bp, "server_cfengine");
548548

549549
pp = BundleSectionAppendPromise(sp, config->input_file,

libpromises/cf3.defs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,13 @@ typedef struct
691691
SyntaxStatus status;
692692
} PromiseTypeSyntax;
693693

694+
typedef enum
695+
{
696+
EVAL_ORDER_UNDEFINED = 0,
697+
EVAL_ORDER_CLASSIC,
698+
EVAL_ORDER_TOP_DOWN
699+
} EvalOrder;
700+
694701
/*************************************************************************/
695702

696703
typedef struct Constraint_ Constraint;

libpromises/cf3parse_logic.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,24 @@ static inline void ParserHandleBlockAttributeRval()
10111011
P.current_namespace = xstrdup(P.rval.item);
10121012
}
10131013
}
1014+
if (StringEqual(P.lval, "evaluation_order"))
1015+
{
1016+
if (P.rval.type != RVAL_TYPE_SCALAR)
1017+
{
1018+
yyerror("evaluation_order must be a constant scalar string");
1019+
}
1020+
else
1021+
{
1022+
if (StringEqual(P.rval.item, "classic"))
1023+
{
1024+
P.current_evaluation_order = EVAL_ORDER_CLASSIC;
1025+
}
1026+
else if (StringEqual(P.rval.item, "top_down"))
1027+
{
1028+
P.current_evaluation_order = EVAL_ORDER_TOP_DOWN;
1029+
}
1030+
}
1031+
}
10141032
}
10151033

10161034
RvalDestroy(P.rval);
@@ -1038,7 +1056,8 @@ static inline void ParserBeginBundleBody()
10381056
P.blockid,
10391057
P.blocktype,
10401058
P.useargs,
1041-
P.filename);
1059+
P.filename,
1060+
P.current_evaluation_order);
10421061
P.currentbundle->offset.line = CURRENT_BLOCKID_LINE;
10431062
P.currentbundle->offset.start = P.offsets.last_block_id;
10441063
}

libpromises/eval_context.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ struct EvalContext_
207207
Seq *events;
208208
} profiler;
209209

210-
EvalContextEvalOrder common_eval_order;
211-
EvalContextEvalOrder agent_eval_order;
210+
EvalOrder common_eval_order;
211+
EvalOrder agent_eval_order;
212212
};
213213

214214
void EvalContextSetConfig(EvalContext *ctx, const GenericAgentConfig *config)
@@ -4062,21 +4062,28 @@ void EvalContextProfilingEnd(EvalContext *ctx, const Policy *policy)
40624062

40634063
// ##############################################################
40644064

4065-
void EvalContextSetCommonEvalOrder(EvalContext *ctx, EvalContextEvalOrder eval_order)
4065+
void EvalContextSetCommonEvalOrder(EvalContext *ctx, EvalOrder eval_order)
40664066
{
40674067
assert(ctx != NULL);
40684068
ctx->common_eval_order = eval_order;
40694069
}
40704070

4071-
void EvalContextSetAgentEvalOrder(EvalContext *ctx, EvalContextEvalOrder eval_order)
4071+
void EvalContextSetAgentEvalOrder(EvalContext *ctx, EvalOrder eval_order)
40724072
{
40734073
assert(ctx != NULL);
40744074
ctx->agent_eval_order = eval_order;
40754075
}
40764076

4077-
bool EvalContextIsClassicOrder(EvalContext *ctx)
4077+
bool EvalContextIsClassicOrder(EvalContext *ctx, const Bundle *bp)
40784078
{
40794079
assert(ctx != NULL);
4080+
assert(bp != NULL);
4081+
4082+
if (bp->evaluation_order != EVAL_ORDER_UNDEFINED)
4083+
{
4084+
// bundle evaluation order overrides common or agent control
4085+
return bp->evaluation_order == EVAL_ORDER_CLASSIC;
4086+
}
40804087

40814088
if (ctx->config->agent_type != AGENT_TYPE_AGENT)
40824089
{

libpromises/eval_context.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ typedef enum
124124
EVAL_OPTION_FULL = 0xFFFFFFFF
125125
} EvalContextOption;
126126

127-
typedef enum
128-
{
129-
EVAL_ORDER_UNDEFINED = 0,
130-
EVAL_ORDER_CLASSIC,
131-
EVAL_ORDER_TOP_DOWN
132-
} EvalContextEvalOrder;
133-
134127
EvalContext *EvalContextNew(void);
135128
void EvalContextDestroy(EvalContext *ctx);
136129

@@ -459,8 +452,8 @@ void EvalContextSetProfiling(EvalContext *ctx, bool profiling);
459452
void EvalContextProfilingStart(EvalContext *ctx);
460453
void EvalContextProfilingEnd(EvalContext *ctx, const Policy *policy);
461454

462-
void EvalContextSetCommonEvalOrder(EvalContext *ctx, EvalContextEvalOrder eval_order);
463-
void EvalContextSetAgentEvalOrder(EvalContext *ctx, EvalContextEvalOrder eval_order);
464-
bool EvalContextIsClassicOrder(EvalContext *ctx);
455+
void EvalContextSetCommonEvalOrder(EvalContext *ctx, EvalOrder eval_order);
456+
void EvalContextSetAgentEvalOrder(EvalContext *ctx, EvalOrder eval_order);
457+
bool EvalContextIsClassicOrder(EvalContext *ctx, const Bundle *bp);
465458

466459
#endif

libpromises/evalfunction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4883,7 +4883,7 @@ static FnCallResult FnCallSelectServers(EvalContext *ctx,
48834883
Policy *select_server_policy = PolicyNew();
48844884
{
48854885
Bundle *bp = PolicyAppendBundle(select_server_policy, NamespaceDefault(),
4886-
"select_server_bundle", "agent", NULL, NULL);
4886+
"select_server_bundle", "agent", NULL, NULL, EVAL_ORDER_UNDEFINED);
48874887
BundleSection *sp = BundleAppendSection(bp, "select_server");
48884888

48894889
BundleSectionAppendPromise(sp, "function", (Rval) { NULL, RVAL_TYPE_NOPROMISEE }, NULL, NULL);

0 commit comments

Comments
 (0)