Skip to content

Commit 6db4861

Browse files
authored
Merge pull request #5942 from victormlg/body_file_control_evalorder
CFE-4598: Added evaluation order in body file control
2 parents 76858a8 + cce7986 commit 6db4861

File tree

21 files changed

+108
-36
lines changed

21 files changed

+108
-36
lines changed

cf-agent/cf-agent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ static void AllClassesReport(const EvalContext *ctx)
16011601
PromiseResult ScheduleAgentOperations(EvalContext *ctx, const Bundle *bp)
16021602
// NB - this function can be called recursively through "methods"
16031603
{
1604-
if (EvalContextIsClassicOrder(ctx))
1604+
if (EvalContextIsClassicOrder(ctx, bp))
16051605
{
16061606
return ScheduleAgentOperationsNormalOrder(ctx, bp);
16071607
}

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
@@ -690,6 +690,13 @@ typedef struct
690690
SyntaxStatus status;
691691
} PromiseTypeSyntax;
692692

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

695702
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: 38 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,54 @@ 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+
const char *EvalContextEvaluationOrderToString(EvalOrder evaluation_order)
4078+
{
4079+
if (evaluation_order == EVAL_ORDER_CLASSIC)
4080+
{
4081+
return "classic";
4082+
}
4083+
if (evaluation_order == EVAL_ORDER_TOP_DOWN)
4084+
{
4085+
return "top_down";
4086+
}
4087+
return "undefined";
4088+
}
4089+
4090+
EvalOrder EvalContextEvaluationOrderFromString(const char *evaluation_order_string)
4091+
{
4092+
if (StringEqual(evaluation_order_string, "classic"))
4093+
{
4094+
return EVAL_ORDER_CLASSIC;
4095+
}
4096+
if (StringEqual(evaluation_order_string, "top_down"))
4097+
{
4098+
return EVAL_ORDER_TOP_DOWN;
4099+
}
4100+
return EVAL_ORDER_UNDEFINED;
4101+
}
4102+
4103+
bool EvalContextIsClassicOrder(EvalContext *ctx, const Bundle *bp)
40784104
{
40794105
assert(ctx != NULL);
4106+
assert(bp != NULL);
4107+
4108+
if (bp->evaluation_order != EVAL_ORDER_UNDEFINED)
4109+
{
4110+
// bundle evaluation order overrides common or agent control
4111+
return bp->evaluation_order == EVAL_ORDER_CLASSIC;
4112+
}
40804113

40814114
if (ctx->config->agent_type != AGENT_TYPE_AGENT)
40824115
{

libpromises/eval_context.h

Lines changed: 5 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,10 @@ 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+
const char *EvalContextEvaluationOrderToString(EvalOrder evaluation_order);
458+
EvalOrder EvalContextEvaluationOrderFromString(const char *evaluation_order_string);
459+
bool EvalContextIsClassicOrder(EvalContext *ctx, const Bundle *bp);
465460

466461
#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)