Skip to content

Commit 377c2b2

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 9b6b3cd commit 377c2b2

6 files changed

Lines changed: 217 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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 = $(CF3_CFLAGS) \
34+
$(DEBUG_CFLAGS) \
35+
$(OPENSSL_CFLAGS) \
36+
$(ENTERPRISE_CFLAGS)
37+
38+
libcf_reactor_la_LIBADD = ../libpromises/libpromises.la
39+
40+
libcf_reactor_la_SOURCES = cf-reactor.c
41+
42+
if !BUILTIN_EXTENSIONS
43+
bin_PROGRAMS = cf-reactor
44+
cf_reactor_LDADD = libcf-reactor.la
45+
cf_reactor_SOURCES =
46+
endif
47+
48+
CLEANFILES = *.gcno *.gcda
49+
50+
#
51+
# Some basic clean ups
52+
#
53+
MOSTLYCLEANFILES = *~ *.orig *.rej

cf-reactor/cf-reactor.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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+
#include <enterprise_extension.h>
36+
37+
#define REACTOR_NOVA_LIBRARY_NAME "cfengine-reactor-nova.so"
38+
39+
typedef int (*ReactorNovaMainFn)(bool no_fork);
40+
41+
static const Component COMPONENT =
42+
{
43+
.name = "cf-reactor",
44+
.website = CF_WEBSITE,
45+
.copyright = CF_COPYRIGHT
46+
};
47+
48+
static const char *const CF_REACTOR_SHORT_DESCRIPTION = "CFEngine event reaction daemon";
49+
50+
static const char *const CF_REACTOR_MANPAGE_LONG_DESCRIPTION =
51+
"cf-reactor is a daemon reacting on events, currently only NOTIFY events from PostgreSQL.";
52+
53+
static const struct option OPTIONS[] =
54+
{
55+
{"debug", no_argument, 0, 'd'},
56+
{"no-fork", no_argument, 0, 'F'},
57+
{"log-level", required_argument, 0, 'g'},
58+
{"help", no_argument, 0, 'h'},
59+
{"inform", no_argument, 0, 'I'},
60+
{"timestamp", no_argument, 0, 'l'},
61+
{"verbose", no_argument, 0, 'v'},
62+
{"version", no_argument, 0, 'V'},
63+
{NULL, 0, 0, '\0'}
64+
};
65+
66+
static const char *const HINTS[] =
67+
{
68+
"Enable debugging output and run in foreground",
69+
"Run as a foreground process (do not fork)",
70+
"Specify how detailed logs should be. Possible values: 'error', 'warning', 'notice', 'info', 'verbose', 'debug'",
71+
"Print the help message",
72+
"Print basic information about actions being taken",
73+
"Log timestamps on each line of log output",
74+
"Output verbose information about the behaviour of the agent",
75+
"Output the version of the software",
76+
NULL
77+
};
78+
79+
ENTERPRISE_FUNC_1ARG_DEFINE_STUB(int, ReactorNovaMain, ARG_UNUSED bool, no_fork)
80+
{
81+
Log(LOG_LEVEL_INFO, "Nova extension library is not available.");
82+
Log(LOG_LEVEL_INFO, "Running open-source cf-reactor.");
83+
return 0;
84+
}
85+
86+
int main(int argc, char *argv[])
87+
{
88+
bool no_fork = false;
89+
90+
extern char *optarg;
91+
int longopt_idx;
92+
int c;
93+
while ((c = getopt_long(argc, argv, "dFg:hIlMvV",
94+
OPTIONS, &longopt_idx))
95+
!= -1)
96+
{
97+
switch (c)
98+
{
99+
case 'd':
100+
LogSetGlobalLevel(LOG_LEVEL_DEBUG);
101+
no_fork = true;
102+
break;
103+
104+
case 'F':
105+
no_fork = true;
106+
break;
107+
108+
case 'g':
109+
LogSetGlobalLevelArgOrExit(optarg);
110+
break;
111+
112+
case 'h':
113+
{
114+
Writer *w = FileWriter(stdout);
115+
WriterWriteHelp(w, &COMPONENT, OPTIONS, HINTS, NULL, false, true);
116+
FileWriterDetach(w);
117+
}
118+
DoCleanupAndExit(EXIT_SUCCESS);
119+
120+
case 'I':
121+
LogSetGlobalLevel(LOG_LEVEL_INFO);
122+
break;
123+
124+
case 'l':
125+
LoggingEnableTimestamps(true);
126+
break;
127+
128+
case 'M':
129+
{
130+
Writer *out = FileWriter(stdout);
131+
ManPageWrite(out, "cf-reactor", time(NULL),
132+
CF_REACTOR_SHORT_DESCRIPTION,
133+
CF_REACTOR_MANPAGE_LONG_DESCRIPTION,
134+
OPTIONS, HINTS,
135+
NULL, false,
136+
true);
137+
FileWriterDetach(out);
138+
DoCleanupAndExit(EXIT_SUCCESS);
139+
}
140+
141+
case 'v':
142+
LogSetGlobalLevel(LOG_LEVEL_VERBOSE);
143+
no_fork = true;
144+
break;
145+
146+
case 'V':
147+
{
148+
Writer *w = FileWriter(stdout);
149+
GenericAgentWriteVersion(w);
150+
FileWriterDetach(w);
151+
}
152+
DoCleanupAndExit(EXIT_SUCCESS);
153+
154+
}
155+
}
156+
157+
return ReactorNovaMain(no_fork);
158+
}

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,7 @@ AC_CONFIG_FILES([Makefile
20152015
cf-net/Makefile
20162016
cf-secret/Makefile
20172017
cf-watchd/Makefile
2018+
cf-reactor/Makefile
20182019
config.post.h
20192020
contrib/vagrant-ci/centos-9s-x64/Makefile
20202021
misc/Makefile

libpromises/prototypes3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ ENTERPRISE_VOID_FUNC_0ARG_DECLARE(void, ReloadHAConfig);
8484

8585
ENTERPRISE_VOID_FUNC_2ARG_DECLARE(void, Nova_ClassHistoryAddContextName, const StringSet *, list, const char *, context_name);
8686
ENTERPRISE_VOID_FUNC_2ARG_DECLARE(void, Nova_ClassHistoryEnable, StringSet **, list, bool, enable);
87+
ENTERPRISE_FUNC_1ARG_DECLARE(int, ReactorNovaMain, bool, no_fork);
8788

8889
/* manual.c */
8990

0 commit comments

Comments
 (0)