Skip to content

Commit

Permalink
filterx: add dirty tracking to FilterXScope
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Apr 19, 2024
1 parent 3a86c1d commit 40fdb48
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/filterx/filterx-eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ filterx_eval_exec_statements(FilterXScope *scope, GList *statements, LogMessage
/* NOTE: we only store the results into the message if the entire evaluation was successful */
success = TRUE;
fail:
filterx_scope_set_dirty(scope);
filterx_eval_set_context(NULL);
return success;
}
Expand Down
29 changes: 29 additions & 0 deletions lib/filterx/filterx-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct _FilterXScope
GArray *variables;
GPtrArray *weak_refs;
gboolean write_protected;
gboolean dirty;
};

static gboolean
Expand Down Expand Up @@ -137,6 +138,18 @@ _lookup_variable(FilterXScope *self, FilterXVariableHandle handle, FilterXVariab
return FALSE;
}

void
filterx_scope_set_dirty(FilterXScope *self)
{
self->dirty = TRUE;
}

gboolean
filterx_scope_is_dirty(FilterXScope *self)
{
return self->dirty;
}

FilterXVariableHandle
filterx_scope_map_variable_to_handle(const gchar *name, FilterXVariableType type)
{
Expand Down Expand Up @@ -199,6 +212,14 @@ filterx_scope_store_weak_ref(FilterXScope *self, FilterXObject *object)
void
filterx_scope_sync(FilterXScope *self, LogMessage *msg)
{

if (!self->dirty)
{
msg_trace("Filterx sync: not syncing as scope is not dirty",
evt_tag_printf("scope", "%p", self));
return;
}

GString *buffer = scratch_buffers_alloc();

for (gint i = 0; i < self->variables->len; i++)
Expand Down Expand Up @@ -255,6 +276,7 @@ filterx_scope_sync(FilterXScope *self, LogMessage *msg)
evt_tag_str("variable", log_msg_get_value_name(filterx_variable_get_nv_handle(v), NULL)));
}
}
self->dirty = FALSE;
}

FilterXScope *
Expand Down Expand Up @@ -290,6 +312,13 @@ filterx_scope_clone(FilterXScope *other)
}
}

if (other->variables->len > 0)
self->dirty = other->dirty;
msg_trace("Filterx clone finished",
evt_tag_printf("scope", "%p", self),
evt_tag_printf("other", "%p", other),
evt_tag_int("dirty", self->dirty),
evt_tag_int("write_protected", self->write_protected));
/* NOTE: we don't clone weak references, those only relate to mutable
* objects, which we are cloning anyway */
return self;
Expand Down
2 changes: 2 additions & 0 deletions lib/filterx/filterx-scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void filterx_variable_mark_declared(FilterXVariable *v);
*/
typedef struct _FilterXScope FilterXScope;

void filterx_scope_set_dirty(FilterXScope *self);
gboolean filterx_scope_is_dirty(FilterXScope *self);
void filterx_scope_sync(FilterXScope *self, LogMessage *msg);

FilterXVariableHandle filterx_scope_map_variable_to_handle(const gchar *name, FilterXVariableType type);
Expand Down

0 comments on commit 40fdb48

Please sign in to comment.