Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions libpromises/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ libpromises_la_SOURCES = \
mod_storage.c mod_storage.h \
mod_knowledge.c mod_knowledge.h \
mod_users.c mod_users.h \
mod_watch.c mod_watch.h \
modes.c \
monitoring_read.c monitoring_read.h \
ornaments.c ornaments.h \
Expand Down
2 changes: 2 additions & 0 deletions libpromises/mod_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <mod_measurement.h>
#include <mod_knowledge.h>
#include <mod_users.h>
#include <mod_watch.h>

#include <conversion.h>
#include <policy.h>
Expand Down Expand Up @@ -549,6 +550,7 @@ const PromiseTypeSyntax *const CF_ALL_PROMISE_TYPES[] =
CF_MEASUREMENT_PROMISE_TYPES, /* mod_measurement.c */
CF_KNOWLEDGE_PROMISE_TYPES, /* mod_knowledge.c */
CF_USERS_PROMISE_TYPES, /* mod_users.c */
CF_WATCH_PROMISE_TYPES, /* mod_watch.c */
};

const int CF3_MODULES = (sizeof(CF_ALL_PROMISE_TYPES) / sizeof(CF_ALL_PROMISE_TYPES[0]));
Expand Down
51 changes: 51 additions & 0 deletions libpromises/mod_watch.c
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_watch.h>

#include <syntax.h>

static const ConstraintSyntax when_constraints[] =
{
CONSTRAINT_SYNTAX_GLOBAL,

/* Row models */
ConstraintSyntaxNewStringList("files_deleted", CF_ANYSTRING, "List of files to watch for 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 watch", SYNTAX_STATUS_NORMAL),
ConstraintSyntaxNewBundle("then", "Bundle to run on event", SYNTAX_STATUS_NORMAL),
ConstraintSyntaxNewNull()
};

const PromiseTypeSyntax CF_WATCH_PROMISE_TYPES[] =
{
PromiseTypeSyntaxNew("watch", "events", CF_EVENT_BODIES, NULL, SYNTAX_STATUS_NORMAL),
PromiseTypeSyntaxNewNull()
};
32 changes: 32 additions & 0 deletions libpromises/mod_watch.h
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_WATCH_H
#define CFENGINE_MOD_WATCH_H

#include <cf3.defs.h>

extern const PromiseTypeSyntax CF_WATCH_PROMISE_TYPES[];

#endif
28 changes: 28 additions & 0 deletions tests/acceptance/32_cf-watchd/syntax.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
bundle agent main
{
reports:
"$(this.promise_filename) Pass";
}

body when file_deleted(filename)
{
files_deleted => { "$(filename)" };
}

bundle agent create_file(filename)
{
files:
"$(filename)" create => "true";
}

bundle watch event_handler
{
events:
"Create /tmp/a"
when => file_deleted("/tmp/a"),
then => create_file("/tmp/a");

"Create /tmp/b"
when => file_deleted("/tmp/b"),
then => create_file("/tmp/b");
}
Loading