-
Notifications
You must be signed in to change notification settings - Fork 201
ENT-14195: Event handling file deletion #6346
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| 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_REACTOR_H | ||
| #define CFENGINE_REACTOR_H | ||
|
|
||
| #include <platform.h> | ||
|
|
||
| /** | ||
| * @brief Shared state for the cf-reactor daemon's single select(2) loop. | ||
| * | ||
| * `all_fds` is a single flat array shared by every event source the daemon | ||
| * watches. Nova's fds always occupy the first `num_nova_fds` slots (Nova | ||
| * owns that sub-range and is the only thing allowed to populate it); any | ||
| * other event source (currently just the watcher subsystem, see watcher.h) | ||
| * appends its own fd(s) after that, and `num_fds` tracks the total number | ||
| * of slots in use. Adding a new event source means: | ||
| * | ||
| * 1. Have it report how many fds it needs, and add that to the capacity | ||
| * computed in ReactorContextInitialize() (reactor_context.c). | ||
| * 2. Give it an Initialize(fds, max_size, num_fds)/HandleEvents(readfds)/ | ||
| * Finalize(void) triplet shaped like ReactorNova*() or EventWatcher*(), | ||
| * and wire the three calls into reactor_context.c next to the existing | ||
| * ones. | ||
| * | ||
| * No other file needs to know how many event sources exist or in what | ||
| * order their fds appear. | ||
| */ | ||
| typedef struct ReactorContext | ||
| { | ||
| int *all_fds; | ||
| size_t all_fds_capacity; | ||
| size_t num_nova_fds; | ||
| size_t num_fds; | ||
|
|
||
| fd_set readfds; | ||
|
Comment on lines
+52
to
+57
Member
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. Clearly indicate which fields are related to reactor-plugin and which are not. |
||
| } ReactorContext; | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||||||||||||||
| /* | ||||||||||||||||||||||
| 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 <file_watcher.h> | ||||||||||||||||||||||
| #include <watcher.h> | ||||||||||||||||||||||
| #include <logging.h> | ||||||||||||||||||||||
| #include <alloc.h> | ||||||||||||||||||||||
| #include <sys/stat.h> | ||||||||||||||||||||||
| #include <errno.h> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // =========== code for EVENT_FILE_DELETED event type =========== | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| typedef struct | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| char *path; | ||||||||||||||||||||||
| bool existed_last_check; | ||||||||||||||||||||||
| } FileWatcherPayload; | ||||||||||||||||||||||
|
Comment on lines
+34
to
+38
Member
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. To me, I would suggest simply:
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /* Only ENOENT/ENOTDIR mean the path genuinely doesn't exist. Any other | ||||||||||||||||||||||
| * stat() failure (e.g. EACCES, ESTALE) is a transient/permission error, not | ||||||||||||||||||||||
| * a deletion, so treat the file as still present rather than misreporting | ||||||||||||||||||||||
| * it as deleted. */ | ||||||||||||||||||||||
| static bool FileExists(const char *path) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| struct stat sb; | ||||||||||||||||||||||
| if (stat(path, &sb) == 0) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return true; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (errno == ENOENT || errno == ENOTDIR) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return false; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Log(LOG_LEVEL_ERR, "Unable to stat '%s' while checking for file deletion: %s", path, GetErrorStr()); | ||||||||||||||||||||||
| return true; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| void *FileWatcherPayloadNew(const char *path) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| FileWatcherPayload *pl = (FileWatcherPayload *) xmalloc(sizeof(FileWatcherPayload)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| pl->path = xstrdup(path); | ||||||||||||||||||||||
| pl->existed_last_check = FileExists(path); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return (void *) pl; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| bool CheckFileExists(void *payload) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| FileWatcherPayload *fwp = payload; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| bool exists_now = FileExists(fwp->path); | ||||||||||||||||||||||
| bool deleted = fwp->existed_last_check && !exists_now; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| fwp->existed_last_check = exists_now; | ||||||||||||||||||||||
| return deleted; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| void DestroyFileWatcherPayload(void *payload) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| FileWatcherPayload *fwp = payload; | ||||||||||||||||||||||
| free(fwp->path); | ||||||||||||||||||||||
| free(fwp); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| 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_FILE_WATCHER_H | ||
| #define CFENGINE_FILE_WATCHER_H | ||
|
|
||
| #include <platform.h> | ||
|
|
||
|
|
||
| void *FileWatcherPayloadNew(const char *path); | ||
| bool CheckFileExists(void *payload); | ||
| void DestroyFileWatcherPayload(void *payload); | ||
|
|
||
| #endif |
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.
Instead of referring to Nova, I think the thing you should refer to is the reactor-plugin. At least to me that is more clear.