-
Notifications
You must be signed in to change notification settings - Fork 201
ENT-14398: Moved event driven cfengine into cf-reactor #6290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
victormlg
wants to merge
1
commit into
cfengine:master
Choose a base branch
from
victormlg:agent-driven-cf-reactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |||||
|
|
||||||
| #include <platform.h> | ||||||
| #include <logging.h> | ||||||
| #include <eval_context.h> | ||||||
| #include <stdio.h> | ||||||
| #include <stdlib.h> | ||||||
| #include <writer.h> | ||||||
|
|
@@ -34,6 +35,16 @@ | |||||
| #include <cleanup.h> | ||||||
| #include <prototypes3.h> | ||||||
|
|
||||||
| /*****************************************************************************/ | ||||||
| /* Globals */ | ||||||
| /*****************************************************************************/ | ||||||
|
|
||||||
| int NO_FORK = false; | ||||||
|
|
||||||
| /*******************************************************************/ | ||||||
| /* Command line options */ | ||||||
| /*******************************************************************/ | ||||||
|
|
||||||
| static const Component COMPONENT = | ||||||
| { | ||||||
| .name = "cf-reactor", | ||||||
|
|
@@ -44,7 +55,8 @@ | |||||
| static const char *const CF_REACTOR_SHORT_DESCRIPTION = "CFEngine event reaction daemon"; | ||||||
|
|
||||||
| static const char *const CF_REACTOR_MANPAGE_LONG_DESCRIPTION = | ||||||
| "cf-reactor is a daemon reacting on events, currently only NOTIFY events from PostgreSQL."; | ||||||
| "cf-reactor is a daemon reacting on events. It watches specific events defined in the policy " | ||||||
| "and runs policy code on reaction to these events."; | ||||||
|
|
||||||
| static const struct option OPTIONS[] = | ||||||
| { | ||||||
|
|
@@ -54,6 +66,7 @@ | |||||
| {"help", no_argument, 0, 'h'}, | ||||||
| {"inform", no_argument, 0, 'I'}, | ||||||
| {"timestamp", no_argument, 0, 'l'}, | ||||||
| {"man", no_argument, 0, 'M'}, | ||||||
| {"verbose", no_argument, 0, 'v'}, | ||||||
| {"version", no_argument, 0, 'V'}, | ||||||
| {NULL, 0, 0, '\0'} | ||||||
|
|
@@ -72,76 +85,111 @@ | |||||
| NULL | ||||||
| }; | ||||||
|
|
||||||
| int main(int argc, char *argv[]) | ||||||
| static GenericAgentConfig *CheckOpts(int argc, char **argv) | ||||||
| { | ||||||
| bool no_fork = false; | ||||||
|
|
||||||
| extern char *optarg; | ||||||
| int longopt_idx; | ||||||
| int c; | ||||||
| GenericAgentConfig *config = GenericAgentConfigNewDefault(AGENT_TYPE_REACTOR, GetTTYInteractive()); | ||||||
|
|
||||||
| int longopt_idx; | ||||||
| while ((c = getopt_long(argc, argv, "dFg:hIlMvV", | ||||||
| OPTIONS, &longopt_idx)) | ||||||
| != -1) | ||||||
| OPTIONS, &longopt_idx)) != -1) | ||||||
| { | ||||||
| switch (c) | ||||||
| { | ||||||
| case 'd': | ||||||
| LogSetGlobalLevel(LOG_LEVEL_DEBUG); | ||||||
| no_fork = true; | ||||||
| NO_FORK = true; | ||||||
| break; | ||||||
|
|
||||||
| case 'F': | ||||||
| no_fork = true; | ||||||
| case 'I': | ||||||
| LogSetGlobalLevel(LOG_LEVEL_INFO); | ||||||
| break; | ||||||
|
|
||||||
| case 'v': | ||||||
| LogSetGlobalLevel(LOG_LEVEL_VERBOSE); | ||||||
| NO_FORK = true; | ||||||
| break; | ||||||
|
|
||||||
| case 'g': | ||||||
| LogSetGlobalLevelArgOrExit(optarg); | ||||||
| break; | ||||||
|
|
||||||
| case 'F': | ||||||
| NO_FORK = true; | ||||||
| break; | ||||||
|
|
||||||
| case 'V': | ||||||
| { | ||||||
| Writer *w = FileWriter(stdout); | ||||||
| GenericAgentWriteVersion(w); | ||||||
| FileWriterDetach(w); | ||||||
| } | ||||||
| DoCleanupAndExit(EXIT_SUCCESS); | ||||||
|
|
||||||
| case 'h': | ||||||
| { | ||||||
| Writer *w = FileWriter(stdout); | ||||||
| WriterWriteHelp(w, &COMPONENT, OPTIONS, HINTS, NULL, false, true); | ||||||
| FileWriterDetach(w); | ||||||
| } | ||||||
| DoCleanupAndExit(EXIT_SUCCESS); | ||||||
| { | ||||||
| Writer *w = FileWriter(stdout); | ||||||
| WriterWriteHelp(w, &COMPONENT, OPTIONS, HINTS, NULL, false, true); | ||||||
| FileWriterDetach(w); | ||||||
| } | ||||||
| DoCleanupAndExit(EXIT_SUCCESS); | ||||||
|
|
||||||
| case 'I': | ||||||
| LogSetGlobalLevel(LOG_LEVEL_INFO); | ||||||
| break; | ||||||
| case 'M': | ||||||
| { | ||||||
| Writer *out = FileWriter(stdout); | ||||||
| ManPageWrite(out, "cf-watchd", time(NULL), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| CF_REACTOR_SHORT_DESCRIPTION, | ||||||
| CF_REACTOR_MANPAGE_LONG_DESCRIPTION, | ||||||
| OPTIONS, HINTS, | ||||||
| NULL, false, | ||||||
| true); | ||||||
| FileWriterDetach(out); | ||||||
| DoCleanupAndExit(EXIT_SUCCESS); | ||||||
| } | ||||||
|
|
||||||
| case 'l': | ||||||
| LoggingEnableTimestamps(true); | ||||||
| break; | ||||||
|
|
||||||
| case 'M': | ||||||
| { | ||||||
| Writer *out = FileWriter(stdout); | ||||||
| ManPageWrite(out, "cf-reactor", time(NULL), | ||||||
| CF_REACTOR_SHORT_DESCRIPTION, | ||||||
| CF_REACTOR_MANPAGE_LONG_DESCRIPTION, | ||||||
| OPTIONS, HINTS, | ||||||
| NULL, false, | ||||||
| true); | ||||||
| FileWriterDetach(out); | ||||||
| DoCleanupAndExit(EXIT_SUCCESS); | ||||||
| } | ||||||
|
|
||||||
| case 'v': | ||||||
| LogSetGlobalLevel(LOG_LEVEL_VERBOSE); | ||||||
| no_fork = true; | ||||||
| /* long options only */ | ||||||
| case 0: | ||||||
| { | ||||||
| // const char *const option_name = OPTIONS[longopt_idx].name; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's some commented out code here |
||||||
| break; | ||||||
| } | ||||||
|
|
||||||
| case 'V': | ||||||
| { | ||||||
| Writer *w = FileWriter(stdout); | ||||||
| GenericAgentWriteVersion(w); | ||||||
| FileWriterDetach(w); | ||||||
| } | ||||||
| DoCleanupAndExit(EXIT_SUCCESS); | ||||||
|
|
||||||
| default: | ||||||
| { | ||||||
| Writer *w = FileWriter(stdout); | ||||||
| WriterWriteHelp(w, &COMPONENT, OPTIONS, HINTS, NULL, false, true); | ||||||
| FileWriterDetach(w); | ||||||
| } | ||||||
| DoCleanupAndExit(EXIT_FAILURE); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return ReactorEnterpriseMain(no_fork); | ||||||
| if (!GenericAgentConfigParseArguments(config, argc - optind, argv + optind)) | ||||||
| { | ||||||
| Log(LOG_LEVEL_ERR, "Too many arguments"); | ||||||
| DoCleanupAndExit(EXIT_FAILURE); | ||||||
| } | ||||||
|
|
||||||
| return config; | ||||||
| } | ||||||
|
|
||||||
| /*****************************************************************************/ | ||||||
|
|
||||||
| int main(int argc, char *argv[]) | ||||||
| { | ||||||
| GenericAgentConfig *config = CheckOpts(argc, argv); | ||||||
| EvalContext *ctx = EvalContextNew(); | ||||||
| GenericAgentConfigApply(ctx, config); | ||||||
|
|
||||||
| int ret = ReactorEnterpriseMain(NO_FORK); | ||||||
|
|
||||||
| GenericAgentFinalize(ctx, config); | ||||||
| CallCleanupFunctions(); | ||||||
|
|
||||||
| return ret; | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| Copyright 2026 Northern.tech AS | ||
|
|
||
| This file is part of CFEngine 3 - written and maintained by Northern.tech AS. | ||
|
|
||
| This program is free software; you can redistribute it and/or modify it | ||
| under the terms of the GNU General Public License as published by the | ||
| Free Software Foundation; version 3. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program; if not, write to the Free Software | ||
| Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
|
|
||
| To the extent this program is licensed as part of the Enterprise | ||
| versions of CFEngine, the applicable Commercial Open Source License | ||
| (COSL) may apply to this file if you as a licensee so wish it. See | ||
| included file COSL.txt. | ||
| */ | ||
|
|
||
| #include <mod_reactor.h> | ||
|
|
||
| #include <syntax.h> | ||
|
|
||
| static const ConstraintSyntax when_constraints[] = | ||
| { | ||
| CONSTRAINT_SYNTAX_GLOBAL, | ||
|
|
||
| /* Row models */ | ||
| ConstraintSyntaxNewStringList("files_deleted", CF_ANYSTRING, "List of files to react for on deletion", SYNTAX_STATUS_NORMAL), | ||
| ConstraintSyntaxNewNull() | ||
| }; | ||
|
|
||
| static const BodySyntax when_body = BodySyntaxNew("when", when_constraints, NULL, SYNTAX_STATUS_NORMAL); | ||
|
|
||
| static const ConstraintSyntax CF_EVENT_BODIES[] = | ||
| { | ||
| ConstraintSyntaxNewBody("when", &when_body, "Event to react to", SYNTAX_STATUS_NORMAL), | ||
| ConstraintSyntaxNewBundle("then", "Bundle to run on event", SYNTAX_STATUS_NORMAL), | ||
| ConstraintSyntaxNewNull() | ||
| }; | ||
|
|
||
| const PromiseTypeSyntax CF_REACTOR_PROMISE_TYPES[] = | ||
| { | ||
| PromiseTypeSyntaxNew("reactor", "events", CF_EVENT_BODIES, NULL, SYNTAX_STATUS_NORMAL), | ||
| PromiseTypeSyntaxNewNull() | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| Copyright 2026 Northern.tech AS | ||
|
|
||
| This file is part of CFEngine 3 - written and maintained by Northern.tech AS. | ||
|
|
||
| This program is free software; you can redistribute it and/or modify it | ||
| under the terms of the GNU General Public License as published by the | ||
| Free Software Foundation; version 3. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program; if not, write to the Free Software | ||
| Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
|
|
||
| To the extent this program is licensed as part of the Enterprise | ||
| versions of CFEngine, the applicable Commercial Open Source License | ||
| (COSL) may apply to this file if you as a licensee so wish it. See | ||
| included file COSL.txt. | ||
| */ | ||
|
|
||
| #ifndef CFENGINE_MOD_REACTOR_H | ||
| #define CFENGINE_MOD_REACTOR_H | ||
|
|
||
| #include <cf3.defs.h> | ||
|
|
||
| extern const PromiseTypeSyntax CF_REACTOR_PROMISE_TYPES[]; | ||
|
|
||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This header is not used