Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
37beeca
Run reactor tests in jenkins
victormlg Oct 27, 2026
5f352d3
Added better logging of the cf-reactor tests
victormlg Oct 27, 2026
51a2014
Fixed out of range scalar value for guest environments
victormlg Oct 28, 2026
f0f66f4
Fixed build against OpenSSL 4
larsewi Oct 28, 2026
23ba797
Made testall fail regular acceptance tests which log errors
aleksandrychev Oct 14, 2026
97d4249
Added fileexists() guards to file reads in acceptance tests
aleksandrychev Oct 15, 2026
5398b14
Indented command output in dcs_passif_output() DEBUG report
aleksandrychev Oct 15, 2026
bbf547b
Added guards to reads of files created later in acceptance tests
aleksandrychev Oct 15, 2026
8af7a04
Renamed 00_basics/def.json test directory to def_json
aleksandrychev Oct 15, 2026
cb51dff
Fixed execresult_action_immediate.cf logging errors
aleksandrychev Oct 15, 2026
f5197a4
Fixed classic_evaluation_custom_promise_types.cf logging errors
aleksandrychev Oct 15, 2026
26fc014
Fixed changes_silent.cf logging errors
aleksandrychev Oct 15, 2026
dd93368
Fixed wrong-bundle-type.cf and ifelse.cf logging errors
aleksandrychev Oct 15, 2026
350760c
Renamed acceptance tests which log errors on purpose to .error.pass.cf
aleksandrychev Oct 15, 2026
22cab40
Fixed linting issues
aleksandrychev Oct 15, 2026
14691f5
Fixed unsafe and check_syntax.cf acceptance tests logging errors
nickanderson Oct 22, 2026
5c6c043
Fixed formatting of acceptance tests
nickanderson Oct 22, 2026
3e5e690
Fixed mapdata_json_pipe.cf logging errors
nickanderson Oct 23, 2026
a73a0c1
Made .error.pass.cf tests respect soft fails and skips
aleksandrychev Oct 26, 2026
4cb9088
Fixed diff_mode_ownership.cf logging errors
nickanderson Oct 28, 2026
bb0b18f
fix stack buffer overflow in SaveAsFile backup path construction
Dhanu-dynamic Oct 18, 2026
72405c5
libpromises: Added empty package_module_wrapper.{c,h}
larsewi Oct 29, 2026
28b3cc3
Moved package module wrapper code from cf-agent to libpromises
larsewi Oct 29, 2026
16ad8db
package_module_wrapper.c: Made PackageWrapperCommunicate() and ParseO…
larsewi Oct 29, 2026
f871307
package_module_wrapper.h: Added doc comments
larsewi Oct 29, 2026
6bba782
Renamed ParseOptions() to PackageModuleFormatOptions()
larsewi Oct 29, 2026
eba270c
Added timeout parameter to NewPackageModuleWrapper()
larsewi Oct 29, 2026
045402d
Fixed cf-reactor users test failing when run as root
victormlg Oct 28, 2026
6c12476
package_module_wrapper.c: Added asserts for pointer arguments
larsewi Oct 29, 2026
9b841d1
cf-reactor: Passed EvalContext to watcher state constructors
larsewi Oct 29, 2026
00b2d52
reactor_transform.c: Added optional extra args to event types
larsewi Oct 29, 2026
92f7d8f
reactor_transform.c: Now fails events promise if watcher state can't …
larsewi Oct 29, 2026
cc474c0
Moved FreePackageManager() from eval_context.c to package_module_wrap…
larsewi Oct 29, 2026
073fd6d
package_module_wrapper.c: Made FreePackageManager() public
larsewi Oct 29, 2026
ca1ff8e
Renamed FreePackageManager() to PackageModuleBodyDestroy()
larsewi Oct 29, 2026
52782b0
package_module_wrapper.c: PackageModuleBodyDestroy() now accepts NULL
larsewi Oct 29, 2026
f381917
package_module_wrapper.c: Added PackageModuleBodyCopy()
larsewi Oct 29, 2026
a3e4645
Merge pull request #6449 from larsewi/openssl4-x509-name
larsewi Oct 30, 2026
97f0547
Merge pull request #6451 from larsewi/reactor-event-types
larsewi Oct 30, 2026
2866b97
Merge pull request #6450 from larsewi/package-module-wrapper
larsewi Oct 30, 2026
fc37174
cf-reactor: Added user_added and user_removed events
larsewi Oct 27, 2026
6734d28
Merge pull request #6405 from aleksandrychev/CFE-3041
olehermanse Oct 30, 2026
bc22e81
Merge pull request #6447 from victormlg/cf-reactor.RunTestsInJenkins
larsewi Oct 30, 2026
34f90cf
Merge pull request #6446 from larsewi/reactor-user-events
larsewi Oct 30, 2026
5ac9805
Merge pull request #6420 from Dhanu-dynamic/saveasfile-backup-path-ov…
larsewi Oct 30, 2026
56c3352
Warned about CMDB keys whose dots are taken as a scope separator
djbclark Nov 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/reactor_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
ln -s "$PWD/cf-reactor/cf-reactor" "$PWD/cf-promises/cf-promises" "$RUNNER_TEMP/bin/"
cd tests/reactor
chmod -R go-w .
CF_BINDIR="$RUNNER_TEMP/bin" sh run.sh
CF_BINDIR="$RUNNER_TEMP/bin" sh run.sh --unsafe
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ stamp-h1
/tests/acceptance/25_cf-execd/Makefile
/tests/acceptance/Makefile
/tests/load/Makefile
/tests/reactor/Makefile
/tests/unit/Makefile
/tests/static-check/Makefile
/tests/valgrind-check/Makefile
Expand Down
224 changes: 6 additions & 218 deletions cf-agent/package_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,123 +47,6 @@
static bool UpdateSinglePackageModuleCache(EvalContext *ctx,
const PackageModuleWrapper *module_wrapper,
UpdateType type, bool force_update);
static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, char **exec_path,
char **script_path, char **script_path_quoted, char **script_exec_opts);
static int NegotiateSupportedAPIVersion(PackageModuleWrapper *wrapper);


void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper)
{
if (wrapper != NULL)
{
free(wrapper->path);
free(wrapper->script_path);
free(wrapper->script_path_quoted);
free(wrapper->script_exec_opts);
free(wrapper->name);
free(wrapper);
}
}

PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module)
{
assert(package_module && package_module->name);

PackageModuleWrapper *wrapper = xmalloc(sizeof(PackageModuleWrapper));

GetPackageModuleExecInfo(package_module, &(wrapper->path),
&(wrapper->script_path), &(wrapper->script_path_quoted),
&(wrapper->script_exec_opts));
wrapper->name = SafeStringDuplicate(package_module->name);
wrapper->package_module = package_module;

if (wrapper->path == NULL)
{
Log(LOG_LEVEL_ERR, "No executable for the package module '%s'", package_module->name);
DeletePackageModuleWrapper(wrapper);
return NULL;
}

/* Check if the given files exist and have the required permissions. */
if (wrapper->script_path != NULL)
{
/* we were given a path to a script to execute with the given
* interpreter */
const char *interpreter_path = wrapper->path;
const char *script_path = wrapper->script_path;

if (access(interpreter_path, X_OK) != 0)
{
Log(LOG_LEVEL_ERR,
"Cannot find package module interpreter at location '%s'"
" or access to the file is restricted: %s",
wrapper->path, GetErrorStr());
DeletePackageModuleWrapper(wrapper);
return NULL;
}
if (access(script_path, R_OK) != 0)
{
Log(LOG_LEVEL_ERR,
"Cannot find package module script at location '%s'"
" or access to the file is restricted: %s",
wrapper->script_path, GetErrorStr());
DeletePackageModuleWrapper(wrapper);
return NULL;
}
}
else if (access(wrapper->path, X_OK) != 0)
{
/* no script path specified --> the given path has to be executable */
Log(LOG_LEVEL_ERR,
"Cannot find package module at location '%s' or access to file is restricted: %s",
wrapper->path, GetErrorStr());
DeletePackageModuleWrapper(wrapper);
return NULL;
}

/* Negotiate API version */
wrapper->supported_api_version = NegotiateSupportedAPIVersion(wrapper);
if (wrapper->supported_api_version != 1)
{
Log(LOG_LEVEL_ERR,
"Unsupported package module wrapper API version: %d",
wrapper->supported_api_version);
DeletePackageModuleWrapper(wrapper);
return NULL;
}

Log(LOG_LEVEL_DEBUG,
"Successfully created package module wrapper for '%s' package module.",
package_module->name);

return wrapper;
}

static int PackageWrapperCommunicate(const PackageModuleWrapper *wrapper, const char *args,
const char *request, Rlist **response)
{
char *all_args = NULL;
if (wrapper->script_path != NULL)
{
if (wrapper->script_exec_opts == NULL)
{
all_args = StringConcatenate(3, wrapper->script_path_quoted, " ", args);
args = all_args;
}
else
{
all_args = StringConcatenate(5, wrapper->script_exec_opts, " ",
wrapper->script_path_quoted, " ", args);
args = all_args;
}
}
int ret = PipeReadWriteData(wrapper->path, args, request, response,
PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC,
PACKAGE_PROMISE_TERMINATION_CHECK_SEC);
free(all_args);

return ret;
}

void UpdatePackagesCache(EvalContext *ctx, bool force_update)
{
Expand Down Expand Up @@ -193,7 +76,8 @@ void UpdatePackagesCache(EvalContext *ctx, bool force_update)
continue;
}

PackageModuleWrapper *module_wrapper = NewPackageModuleWrapper(module);
PackageModuleWrapper *module_wrapper =
NewPackageModuleWrapper(module, PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC);

if (!module_wrapper)
{
Expand Down Expand Up @@ -278,24 +162,6 @@ static void FreePackageInfo(PackageInfo *package_info)
}
}

static char *ParseOptions(Rlist *options)
{
if (RlistIsNullList(options))
{
return SafeStringDuplicate("");
}

Buffer *data = BufferNew();
for (Rlist *rp = options; rp != NULL; rp = rp->next)
{
char *value = RlistScalarValue(rp);
BufferAppendString(data, "options=");
BufferAppendString(data, value);
BufferAppendString(data, "\n");
}
return BufferClose(data);
}

static PackageInfo *ParseAndCheckPackageDataReply(const Rlist *data)
{
PackageInfo * package_data = xcalloc(1, sizeof(PackageInfo));
Expand Down Expand Up @@ -386,35 +252,6 @@ static PackageInfo *ParseAndCheckPackageDataReply(const Rlist *data)
return package_data;
}

static int NegotiateSupportedAPIVersion(PackageModuleWrapper *wrapper)
{
assert(wrapper);

Log(LOG_LEVEL_DEBUG, "Getting supported API version.");

int api_version = -1;

Rlist *response = NULL;
if (PackageWrapperCommunicate(wrapper, "supports-api-version", "",
&response) != 0)
{
Log(LOG_LEVEL_INFO,
"Error occurred while getting supported API version.");
return -1;
}

if (response)
{
if (RlistLen(response) == 1)
{
api_version = atoi(RlistScalarValue(response));
Log(LOG_LEVEL_DEBUG, "package wrapper API version: %d", api_version);
}
RlistDestroy(response);
}
return api_version;
}

/* IMPORTANT: this might not return all the data we need like version
or architecture but package name MUST be known. */
static
Expand All @@ -426,7 +263,7 @@ PackageInfo *GetPackageData(const char *name, const char *version,

Log(LOG_LEVEL_DEBUG, "Getting package '%s' data.", name);

char *options_str = ParseOptions(options);
char *options_str = PackageModuleFormatOptions(options);
char *ver = version ?
StringFormat("Version=%s\n", version) : NULL;
char *arch = architecture ?
Expand Down Expand Up @@ -473,55 +310,6 @@ PackageInfo *GetPackageData(const char *name, const char *version,
return package_data;
}

static void GetPackageModuleExecInfo(const PackageModuleBody *package_module, char **exec_path,
char **script_path, char **script_path_quoted,
char **script_exec_opts)
{

assert(exec_path != NULL);
assert(script_path != NULL);
assert(script_path_quoted != NULL);

char *package_module_path = NULL;

if (package_module->module_path != NULL && !StringEqual(package_module->module_path, ""))
{
package_module_path = xstrdup(package_module->module_path);
}
else
{
package_module_path = StringFormat("%s%c%s%c%s%c%s", GetWorkDir(), FILE_SEPARATOR,
"modules", FILE_SEPARATOR, "packages", FILE_SEPARATOR,
package_module->name);
}

if (package_module->interpreter && !StringEqual(package_module->interpreter, ""))
{
*script_path = package_module_path;
*script_path_quoted = Path_GetQuoted(*script_path);

if (strchr(package_module->interpreter, ' ') == NULL)
{
/* No spaces in the 'interpreter' string, easy! Just interpreter path given, no opts. */
*exec_path = xstrdup(package_module->interpreter);
*script_exec_opts = NULL;
}
else
{
/* we need to split the interpreter command from the (potential)
* interpreter args */
ArgGetExecutableAndArgs(package_module->interpreter, exec_path, script_exec_opts);
}
}
else
{
*exec_path = package_module_path;
*script_path = NULL;
*script_path_quoted = NULL;
*script_exec_opts = NULL;
}
}

static int IsPackageInCache(EvalContext *ctx,
const PackageModuleWrapper *module_wrapper,
const char *name, const char *ver, const char *arch)
Expand Down Expand Up @@ -780,7 +568,7 @@ bool UpdateCache(Rlist* options, const PackageModuleWrapper *wrapper,

Log(LOG_LEVEL_DEBUG, "Updating cache: %d", type);

char *options_str = ParseOptions(options);
char *options_str = PackageModuleFormatOptions(options);
Rlist *response = NULL;

const char *req_type = NULL;
Expand Down Expand Up @@ -880,7 +668,7 @@ PromiseResult RemovePackage(const char *name, Rlist* options,

Log(LOG_LEVEL_DEBUG, "Removing package '%s'", name);

char *options_str = ParseOptions(options);
char *options_str = PackageModuleFormatOptions(options);
char *ver = version ?
StringFormat("Version=%s\n", version) : NULL;
char *arch = architecture ?
Expand Down Expand Up @@ -925,7 +713,7 @@ static PromiseResult InstallPackageGeneric(Rlist *options,
type == PACKAGE_TYPE_FILE ? "file" : "repo",
packages_list_formatted);

char *options_str = ParseOptions(options);
char *options_str = PackageModuleFormatOptions(options);
char *request = StringFormat("%s%s", options_str, packages_list_formatted);

PromiseResult res = PROMISE_RESULT_CHANGE;
Expand Down
16 changes: 1 addition & 15 deletions cf-agent/package_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#define PACKAGE_MODULE_H

#include <cf3.defs.h>
#include <package_module_wrapper.h>

//TODO: use promise expireafter instead
#define PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC 4 * 3600 /* 4 hours timeout */
#define PACKAGE_PROMISE_TERMINATION_CHECK_SEC 1

#define GLOBAL_PACKAGE_PROMISE_LOCK_NAME "new_packages_promise_lock"

Expand All @@ -54,17 +54,6 @@ typedef struct
char *message;
} PackageError;

typedef struct
{
char *name;
char *path;
char *script_path;
char *script_path_quoted;
char *script_exec_opts;
PackageModuleBody *package_module;
int supported_api_version;
} PackageModuleWrapper;

typedef struct
{
CfLock g_lock;
Expand All @@ -88,9 +77,6 @@ PromiseResult HandleAbsentPromiseAction(EvalContext *ctx,

void UpdatePackagesCache(EvalContext *ctx, bool force_update);

PackageModuleWrapper *NewPackageModuleWrapper(PackageModuleBody *package_module);
void DeletePackageModuleWrapper(PackageModuleWrapper *wrapper);

PackagePromiseGlobalLock AcquireGlobalPackagePromiseLock(EvalContext *ctx);
void YieldGlobalPackagePromiseLock(PackagePromiseGlobalLock lock);

Expand Down
3 changes: 2 additions & 1 deletion cf-agent/verify_new_packages.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ PromiseResult HandleNewPackagePromiseType(EvalContext *ctx, const Promise *pp, c
}

PackageModuleWrapper *package_module =
NewPackageModuleWrapper(a->new_packages.module_body);
NewPackageModuleWrapper(a->new_packages.module_body,
PACKAGE_PROMISE_SCRIPT_TIMEOUT_SEC);

if (package_module == NULL)
{
Expand Down
1 change: 1 addition & 0 deletions cf-reactor/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ libcf_reactor_la_SOURCES = \
reactor_context.c reactor_context.h \
reactor_transform.c reactor_transform.h \
stoppable_thread.c stoppable_thread.h \
user_watcher.c user_watcher.h \
wakeup_channel.c wakeup_channel.h \
watcher.c watcher.h

Expand Down
4 changes: 2 additions & 2 deletions cf-reactor/file_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct
} FileWatcherState;


void *FileWatcherStateNew(const Rlist *args)
void *FileWatcherStateNew(ARG_UNUSED const EvalContext *ctx, const Rlist *args)
{
assert(args != NULL);
const char *path = RlistScalarValue(args);
Expand All @@ -93,7 +93,7 @@ void *FileWatcherStateNew(const Rlist *args)
return fws;
}

void *FileWatcherSizeStateNew(const Rlist *args)
void *FileWatcherSizeStateNew(ARG_UNUSED const EvalContext *ctx, const Rlist *args)
{
assert(args != NULL && args->next != NULL);
const char *path = RlistScalarValue(args);
Expand Down
4 changes: 2 additions & 2 deletions cf-reactor/file_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include <watcher.h> /* WatcherCheckResult */


void *FileWatcherStateNew(const Rlist *args);
void *FileWatcherSizeStateNew(const Rlist *args);
void *FileWatcherStateNew(const EvalContext *ctx, const Rlist *args);
void *FileWatcherSizeStateNew(const EvalContext *ctx, const Rlist *args);
void FileWatcherStateDestroy(void *state);

WatcherCheckResult FileWatcherCheckFileDeleted(void *state);
Expand Down
Loading
Loading