Skip to content

Commit 69b1f52

Browse files
committed
Store override_immutable variable in EvalContext
This way we don't have to explicitly pass it to a gazillion functions. Ticket: ENT-10961, CFE-1840 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent 081704d commit 69b1f52

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

cf-agent/verify_files.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
static PromiseResult FindFilePromiserObjects(EvalContext *ctx, const Promise *pp);
6666
static PromiseResult VerifyFilePromise(EvalContext *ctx, char *path, const Promise *pp);
6767
static PromiseResult WriteContentFromString(EvalContext *ctx, const char *path, const Attributes *attr,
68-
const Promise *pp, bool override_immutable);
68+
const Promise *pp);
6969

7070
/*****************************************************************************/
7171

@@ -405,7 +405,7 @@ static PromiseResult VerifyFilePromise(EvalContext *ctx, char *path, const Promi
405405
/* If we encounter any promises to mutate the file and the immutable
406406
* attribute in body fsattrs is "true", we will override the immutable bit
407407
* by temporarily clearing it when ever needed. */
408-
const bool override_immutable = a.havefsattrs && a.fsattrs.haveimmutable && a.fsattrs.immutable && is_immutable;
408+
EvalContextOverrideImmutableSet(ctx, a.havefsattrs && a.fsattrs.haveimmutable && a.fsattrs.immutable && is_immutable);
409409

410410
if (lstat(changes_path, &oslb) == -1) /* Careful if the object is a link */
411411
{
@@ -616,7 +616,7 @@ static PromiseResult VerifyFilePromise(EvalContext *ctx, char *path, const Promi
616616
Log(LOG_LEVEL_VERBOSE, "Replacing '%s' with content '%s'",
617617
path, a.content);
618618

619-
PromiseResult render_result = WriteContentFromString(ctx, path, &a, pp, override_immutable);
619+
PromiseResult render_result = WriteContentFromString(ctx, path, &a, pp);
620620
result = PromiseResultUpdate(result, render_result);
621621

622622
goto exit;
@@ -710,6 +710,9 @@ static PromiseResult VerifyFilePromise(EvalContext *ctx, char *path, const Promi
710710
}
711711

712712
exit:
713+
/* Reset this to false before next file promise */
714+
EvalContextOverrideImmutableSet(ctx, false);
715+
713716
free(chrooted_path);
714717
if (AttrHasNoAction(&a))
715718
{
@@ -765,7 +768,7 @@ static PromiseResult VerifyFilePromise(EvalContext *ctx, char *path, const Promi
765768
/*****************************************************************************/
766769

767770
static PromiseResult WriteContentFromString(EvalContext *ctx, const char *path, const Attributes *attr,
768-
const Promise *pp, bool override_immutable)
771+
const Promise *pp)
769772
{
770773
assert(path != NULL);
771774
assert(attr != NULL);
@@ -793,6 +796,7 @@ static PromiseResult WriteContentFromString(EvalContext *ctx, const char *path,
793796

794797
if (!HashesMatch(existing_content_digest, promised_content_digest, CF_DEFAULT_DIGEST))
795798
{
799+
bool override_immutable = EvalContextOverrideImmutableGet(ctx);
796800
if (!MakingChanges(ctx, pp, attr, &result,
797801
"update file '%s' with content '%s'",
798802
path, attr->content))

libpromises/eval_context.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,19 @@ struct EvalContext_
192192
RemoteVarPromisesMap *remote_var_promises;
193193

194194
bool dump_reports;
195+
bool override_immutable;
195196
};
196197

198+
void EvalContextOverrideImmutableSet(EvalContext *ctx, bool should_override)
199+
{
200+
ctx->override_immutable = should_override;
201+
}
202+
203+
bool EvalContextOverrideImmutableGet(EvalContext *ctx)
204+
{
205+
return ctx->override_immutable;
206+
}
207+
197208
void EvalContextSetConfig(EvalContext *ctx, const GenericAgentConfig *config)
198209
{
199210
assert(ctx != NULL);

libpromises/eval_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ void EvalContextHeapPersistentSave(EvalContext *ctx, const char *name, unsigned
128128
void EvalContextHeapPersistentRemove(const char *context);
129129
void EvalContextHeapPersistentLoadAll(EvalContext *ctx);
130130

131+
void EvalContextOverrideImmutableSet(EvalContext *ctx, bool should_override);
132+
bool EvalContextOverrideImmutableGet(EvalContext *ctx);
133+
131134
/**
132135
* Sets negated classes (persistent classes that should not be defined).
133136
*

0 commit comments

Comments
 (0)