Skip to content

Commit ac41988

Browse files
committed
Moved cf-reactor binary to core
Changelog: Title Ticket: ENT-14275 Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent f364c34 commit ac41988

5 files changed

Lines changed: 224 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ stamp-h1
4444
/cf-testd/Makefile
4545
/cf-upgrade/Makefile
4646
/cf-watchd/Makefile
47+
/cf-reactor/Makefile
4748
/contrib/vagrant-ci/centos-9s-x64/Makefile
4849
/examples/Makefile
4950
/ext/Makefile
@@ -115,6 +116,8 @@ xml_tmp_suite
115116
/cf-upgrade/cf-upgrade.exe
116117
/cf-watchd/cf-watchd
117118
/cf-watchd/cf-watchd.exe
119+
/cf-reactor/cf-reactor
120+
/cf-reactor/cf-reactor.exe
118121
/ext/rpmvercmp
119122
/ext/rpmvercmp.exe
120123

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SUBDIRS = \
4646
cf-net \
4747
cf-secret \
4848
cf-watchd \
49+
cf-reactor \
4950
misc \
5051
python \
5152
ext \

cf-reactor/Makefile.am

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Copyright 2026 Northern.tech AS
3+
#
4+
# This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5+
#
6+
# This program is free software; you can redistribute it and/or modify it
7+
# under the terms of the GNU General Public License as published by the
8+
# Free Software Foundation; version 3.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; if not, write to the Free Software
17+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18+
#
19+
# To the extent this program is licensed as part of the Enterprise
20+
# versions of CFEngine, the applicable Commercial Open Source License
21+
# (COSL) may apply to this file if you as a licensee so wish it. See
22+
# included file COSL.txt.
23+
#
24+
noinst_LTLIBRARIES = libcf-reactor.la
25+
26+
AM_CPPFLAGS = -I$(srcdir)/../libpromises -I$(srcdir)/../libntech/libutils \
27+
-I$(srcdir)/../libcfecompat \
28+
-I$(srcdir)/../libcfnet \
29+
$(OPENSSL_CPPFLAGS) \
30+
$(PCRE2_CPPFLAGS) \
31+
$(ENTERPRISE_CPPFLAGS)
32+
33+
AM_CFLAGS = @CFLAGS@ \
34+
$(OPENSSL_CFLAGS) \
35+
$(ENTERPRISE_CFLAGS)
36+
37+
libcf_reactor_la_LIBADD = ../libpromises/libpromises.la
38+
39+
libcf_reactor_la_SOURCES = cf-reactor.c
40+
41+
if !BUILTIN_EXTENSIONS
42+
bin_PROGRAMS = cf-reactor
43+
cf_reactor_LDADD = libcf-reactor.la
44+
cf_reactor_SOURCES =
45+
endif
46+
47+
CLEANFILES = *.gcno *.gcda
48+
49+
#
50+
# Some basic clean ups
51+
#
52+
MOSTLYCLEANFILES = *~ *.orig *.rej

cf-reactor/cf-reactor.c

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
Copyright 2026 Northern.tech AS
3+
4+
This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5+
6+
This program is free software; you can redistribute it and/or modify it
7+
under the terms of the GNU General Public License as published by the
8+
Free Software Foundation; version 3.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, write to the Free Software
17+
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18+
19+
To the extent this program is licensed as part of the Enterprise
20+
versions of CFEngine, the applicable Commercial Open Source License
21+
(COSL) may apply to this file if you as a licensee so wish it. See
22+
included file COSL.txt.
23+
*/
24+
25+
26+
#include <platform.h>
27+
#include <logging.h>
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include <writer.h>
31+
#include <config.h>
32+
#include <generic_agent.h>
33+
#include <man.h>
34+
#include <cleanup.h>
35+
36+
#define REACTOR_NOVA_LIBRARY_NAME "cfengine-reactor-nova.so"
37+
38+
typedef int (*ReactorNovaMainFn)(bool no_fork);
39+
40+
static const Component COMPONENT =
41+
{
42+
.name = "cf-reactor",
43+
.website = CF_WEBSITE,
44+
.copyright = CF_COPYRIGHT
45+
};
46+
47+
static const char *const CF_REACTOR_SHORT_DESCRIPTION = "CFEngine event reaction daemon";
48+
49+
static const char *const CF_REACTOR_MANPAGE_LONG_DESCRIPTION =
50+
"cf-reactor is a daemon reacting on events, currently only NOTIFY events from PostgreSQL.";
51+
52+
static const struct option OPTIONS[] =
53+
{
54+
{"debug", no_argument, 0, 'd'},
55+
{"no-fork", no_argument, 0, 'F'},
56+
{"log-level", required_argument, 0, 'g'},
57+
{"help", no_argument, 0, 'h'},
58+
{"inform", no_argument, 0, 'I'},
59+
{"timestamp", no_argument, 0, 'l'},
60+
{"verbose", no_argument, 0, 'v'},
61+
{"version", no_argument, 0, 'V'},
62+
{NULL, 0, 0, '\0'}
63+
};
64+
65+
static const char *const HINTS[] =
66+
{
67+
"Enable debugging output and run in foreground",
68+
"Run as a foreground process (do not fork)",
69+
"Specify how detailed logs should be. Possible values: 'error', 'warning', 'notice', 'info', 'verbose', 'debug'",
70+
"Print the help message",
71+
"Print basic information about actions being taken",
72+
"Log timestamps on each line of log output",
73+
"Output verbose information about the behaviour of the agent",
74+
"Output the version of the software",
75+
NULL
76+
};
77+
78+
int main(int argc, char *argv[])
79+
{
80+
bool no_fork = false;
81+
82+
extern char *optarg;
83+
int longopt_idx;
84+
int c;
85+
while ((c = getopt_long(argc, argv, "dFg:hIlMvV",
86+
OPTIONS, &longopt_idx))
87+
!= -1)
88+
{
89+
switch (c)
90+
{
91+
case 'd':
92+
LogSetGlobalLevel(LOG_LEVEL_DEBUG);
93+
no_fork = true;
94+
break;
95+
96+
case 'F':
97+
no_fork = true;
98+
break;
99+
100+
case 'g':
101+
LogSetGlobalLevelArgOrExit(optarg);
102+
break;
103+
104+
case 'h':
105+
{
106+
Writer *w = FileWriter(stdout);
107+
WriterWriteHelp(w, &COMPONENT, OPTIONS, HINTS, NULL, false, true);
108+
FileWriterDetach(w);
109+
}
110+
DoCleanupAndExit(EXIT_SUCCESS);
111+
112+
case 'I':
113+
LogSetGlobalLevel(LOG_LEVEL_INFO);
114+
break;
115+
116+
case 'l':
117+
LoggingEnableTimestamps(true);
118+
break;
119+
120+
case 'M':
121+
{
122+
Writer *out = FileWriter(stdout);
123+
ManPageWrite(out, "cf-reactor", time(NULL),
124+
CF_REACTOR_SHORT_DESCRIPTION,
125+
CF_REACTOR_MANPAGE_LONG_DESCRIPTION,
126+
OPTIONS, HINTS,
127+
NULL, false,
128+
true);
129+
FileWriterDetach(out);
130+
DoCleanupAndExit(EXIT_SUCCESS);
131+
}
132+
133+
case 'v':
134+
LogSetGlobalLevel(LOG_LEVEL_VERBOSE);
135+
no_fork = true;
136+
break;
137+
138+
case 'V':
139+
{
140+
Writer *w = FileWriter(stdout);
141+
GenericAgentWriteVersion(w);
142+
FileWriterDetach(w);
143+
}
144+
DoCleanupAndExit(EXIT_SUCCESS);
145+
146+
}
147+
}
148+
149+
void *handle = extension_library_open(REACTOR_NOVA_LIBRARY_NAME);
150+
if (!handle)
151+
{
152+
Log(LOG_LEVEL_INFO, "Nova extension library '%s' not loaded or not available.", REACTOR_NOVA_LIBRARY_NAME);
153+
Log(LOG_LEVEL_INFO, "Running open-source cf-reactor.");
154+
return 0;
155+
}
156+
157+
ReactorNovaMainFn ReactorNovaMain = (ReactorNovaMainFn) shlib_load(handle, "ReactorNovaMain");
158+
if (!ReactorNovaMain)
159+
{
160+
Log(LOG_LEVEL_ERR, "Failed to load ReactorNovaMain symbol from '%s'.", REACTOR_NOVA_LIBRARY_NAME);
161+
extension_library_close(handle);
162+
return 1;
163+
}
164+
165+
166+
return ReactorNovaMain(no_fork);
167+
}

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,7 @@ AC_CONFIG_FILES([Makefile
20052005
cf-net/Makefile
20062006
cf-secret/Makefile
20072007
cf-watchd/Makefile
2008+
cf-reactor/Makefile
20082009
config.post.h
20092010
contrib/vagrant-ci/centos-9s-x64/Makefile
20102011
misc/Makefile

0 commit comments

Comments
 (0)