3418 Commits

Author SHA1 Message Date
Rainer Gerhards
4c086ed78c
omsendertrack: stop towards full completion of module.
Work towards full completion of the module’s interface as it exits PoC.
The new name senderid (formerly: template) matches intent (identify a
sender, not an output format) and avoids confusion.  Also make state
persistence safer via atomic writes.

Merged a bit pre-completion in order to get a static analyzer fix
into the main code base. Some additional cleanup PR will follow.
State is much cleaner now than in PoC.

Impact: Configs must use senderid=; statefile is now required. Tests
and docs updated.

Before/After: action(... template="name") -> action(... senderid="name").

Technical details:
- Replace the config parameter and instance field; drop legacy template
  parsing in parseSelectorAct. The module now reads only senderid=.
- Enforce required statefile (descriptor + runtime) and cache a temp
  path "<statefile>.tmp" to ensure rename() is atomic. Provide a
  one-time fallback build if the cache is missing (e.g., reload flow).
- Add built-in template "StdOmSenderTrack-senderid" yielding
  "%fromhost-ip%" and use it as the default senderid template.
- Improve memory ownership (free cached temp path/default template) and
  keep existing locking/queue semantics unchanged.
- Update tests to use senderid= and prune PoC doc note accordingly.

see also: https://github.com/rsyslog/rsyslog/issues/5599
2025-08-25 15:51:58 +02:00
Rainer Gerhards
6521000e12 immark: document config cleanup
Explain release of mark message and ruleset strings to prevent leaks on reload.\n\nAI-Agent: ChatGPT
2025-08-23 08:43:19 +02:00
Rainer Gerhards
186cdf3548
Merge pull request #6009 from rsyslog/codex/analyze-and-patch-invalid-pointer-bug
imjournal: initialize instance fields to avoid invalid free
2025-08-22 16:18:27 +02:00
Rainer Gerhards
35f508a085
imjournal: initialize instance fields to avoid invalid free
createInstance() left stateFile and bMain uninitialized. When a
statefile was configured, activateCnf() attempted to free the garbage
pointer, leading to free(): invalid pointer at startup. Initialize
these fields to sane defaults.

Fixes https://github.com/rsyslog/rsyslog/issues/5730

AI-Agent: ChatGPT
2025-08-22 14:04:57 +02:00
Rainer Gerhards
3e64f45bb8
Merge pull request #6002 from rgerhards/statan2
mmaitag: fix potential memory leak
2025-08-22 12:45:55 +02:00
Rainer Gerhards
d8d0da9255
mmaitag: fix potential memory leak
This was detected by clang static analyzer.
2025-08-22 12:39:41 +02:00
Rainer Gerhards
7d3ff39e88 atomic: remove trailing semicolons from helper macros
Trailing semicolons in atomic helper macros caused double
semicolons when the macros expanded, producing build warnings.
Macros now omit semicolons and call sites add them explicitly.
STATSCOUNTER_DEF updated to terminate the generated mutex line.

AI-Agent: ChatGPT
2025-08-19 16:06:44 +02:00
xietangxin
dc561451d7 imjournal: fix double sd_journal_close() during thread cancellation
When the main thread cancel imjournal thread, the thread exits without
setting sd_journal to NULL because sd_journal_close() contain cancel point.
This leads to a double free scenario where:

1. The thread cancel occurs during sd_journal_close()
2. The main thread then calls imjournal's afterrun function
3. sd_journal_close() is called again on the already-freed sd_journal
2025-08-18 20:14:09 +08:00
Rainer Gerhards
3bd81ac6d6
ommysql: remove long-standing non-needed TODO item
This item was create in 2007 and has proven in ~20yrs of practice
to be no issue. Even more so, this is now in legacy code that will
no longer be updated at all. So the TODO no longer applies and could
be removed.
2025-08-14 09:22:14 +02:00
google-labs-jules[bot]
737440ed46
ommysql: drop global rwlock_hmysql, revert a3b2983
Removed the global pthread_rwlock_t rwlock_hmysql and related locking
around worker-local MYSQL *hmysql handles. Each worker owns its handle
exclusively, so no cross-thread access occurs and the global lock adds
unnecessary overhead.

Commit a3b2983 (2021) introduced this lock without clearly stating the
underlying issue. A thorough architectural review and targeted analysis
found no flaw in rsyslog’s code or in the mariadb/mysql client libraries.
Web research also showed no known relevant defects. The most plausible
explanation is that the original change addressed a CI-induced race,
which would be consistent with other CI flake fixes we have made in
recent years.

Given the absence of a reproducible problem and the fact that the
locking code itself introduced theoretical races (never observed in
practice), we are reverting a3b2983’s behavior. We will monitor for
any regressions.

closes https://github.com/rsyslog/rsyslog/issues/5890
2025-08-13 12:50:40 +02:00
Rainer Gerhards
0db4f4b9ed omazureeventhubs: add Doxygen docs for proton thread and flow (NFC)
Add concise Doxygen \brief blocks and inline comments to explain the
qpid-proton integration and worker interaction. This improves
maintainability and lowers ramp-up time for contributors.

Key additions:
- Document connection lifecycle: openProton(), closeProton(),
  setupProtonHandle().
- Document async model: proton_run_thread(), proton_thread(),
  handleProton(), handleProtonDelivery().
- Document batching/ack path: writeProton() and commitTransaction().
- Explain the 100 ms sleep to avoid busy waiting.

Style and housekeeping:
- Split DEFobjCurrIf(...) macros onto separate lines.
- Fix indentation of azureStats declaration.
- Update copyright header to 2014-2025.

Behavior unchanged; comments and formatting only.
2025-08-11 13:01:48 +02:00
619b5983c7 omazurevenethubs: fix compiler warning
- docker: add libqpid-proton build deps to ubuntu/24.04 base container
- CI: build omazureventhubs in run_checks ubuntu/24.04

closes: https://github.com/rsyslog/rsyslog/issues/5895
2025-08-04 12:43:45 +02:00
Rainer Gerhards
11bf43a1a8
omysql: better doc to clarify mutex use
We need to validate the locking method - in theory, multiple access to
the mysql handle should not be possible, because instance data is
worker-local. However, the following 2021 commit suggests there were some
issue. I tend to say the commit was wrong, but this needs to be checked
in more depth, while we need some better doc on the current locking method
right now. So we document existing and valid behaviour and will follow up later.

related commit:
a3b2983342
2025-08-01 17:13:32 +02:00
Rainer Gerhards
8781fd1885
Merge pull request #5871 from Cropi/imjournal-fmode
imjournal: fix vulnerability in state file creation
2025-07-31 12:45:18 +02:00
Rainer Gerhards
a82fcd0d9c
parser: add checkParserInst hook for pre-registration validation
Introduce a new lifecycle callback—`checkParserInst`—to perform
configuration sanity checks on parser instances immediately after they’re
created. This establishes a standardized validation point (similar to
`checkCnf` in other module types) without altering existing parser logic.

By wiring `checkParserInst` into:
- the module template (macros for definition and registration),
- the module loader (`doModInit`) with graceful fallback,
- the runtime configuration flow (`rsconf.c`) just after
  `newParserInst`,

and by providing empty stubs in all current parser modules (contrib and
plugins), we now have a clear, uniform spot to add parser-specific
validation rules in subsequent patches. This improves future
maintainability and robustness of parser configuration handling.
2025-07-31 08:26:50 +02:00
Cropi
44a7d5c6a0 imjournal: fix vulnerability in state file creation
Initialize cs.fCreateMode to 0644 instead of -1 to prevent state files
from being created with all permission bits set when legacy configuration
is used. The setModCnf function is only called with modern configuration,
leaving cs.fCreateMode at -1 for legacy configs, which results in wrong
open() calls.
2025-07-28 09:01:01 +02:00
Rainer Gerhards
d19086dd7e
Merge pull request #5803 from rsyslog/codex/review-and-fix-mmaitag.c-issues
Improve mmaitag memory handling
2025-07-17 20:31:06 +02:00
Rainer Gerhards
45156364a7
fix mmaitag provider handling and memory safety 2025-07-17 17:09:38 +02:00
Rainer Gerhards
a5c4d26940
omelasticsearch fix: Handle HTTP 401/403 auth errors
The omelasticsearch module previously failed to correctly handle HTTP
error status codes returned by the server. The logic checked for
libcurl transport errors but explicitly ignored
'CURLE_HTTP_RETURNED_ERROR', causing server-side errors to be
treated as successful submissions.

This led to silent failures in critical scenarios, especially
authentication (401 Unauthorized) and authorization (403
Forbidden) errors. The plugin would not suspend or report an
error, and data could be lost without any clear error indication.

This commit resolves the issue by:
- Retrieving the HTTP status code after each request using
  'curl_easy_getinfo'.
- Adding an explicit check for 401 and 403 status codes.
- Logging a specific "authentication failed" error and suspending
  the plugin if these errors are detected.

This ensures that users receive immediate and clear feedback on
authentication problems, preventing silent data loss and aiding in
faster troubleshooting.

With AI support: Codex, Gemini
2025-07-17 10:35:25 +02:00
Rainer Gerhards
b326c76f45 style: normalize C source formatting via clang-format (PoC)
This commit applies the new canonical formatting style using `clang-format` with custom settings (notably 4-space indentation), as part of our shift toward automated formatting normalization.

⚠️ No functional changes are included — only whitespace and layout modifications as produced by `clang-format`.

This change is part of the formatting modernization strategy discussed in:
https://github.com/rsyslog/rsyslog/issues/5747

Key context:
- Formatting is now treated as a disposable view, normalized via tooling.
- The `.clang-format` file defines the canonical style.
- A fixup script (`devtools/format-code.sh`) handles remaining edge cases.
- Formatting commits are added to `.git-blame-ignore-revs` to reduce noise.
- Developers remain free to format code however they prefer locally.
2025-07-16 13:56:21 +02:00
Rainer Gerhards
fb51433919
feat: introduce mmaitag PoC with Gemini AI provider (#5754)
This commit adds the initial implementation of the `mmaitag` module,
a pluggable AI-based message classification processor.

The module supports two providers:
- `gemini`: uses the Gemini API via libcurl and JSON-C
- `gemini_mock`: a deterministic in-memory mock used for testing

Each log message is classified individually and tagged with a label
stored in a configurable message variable (default: `$.aitag`).

Included:
- Provider abstraction layer (`ai_provider.h`)
- Gemini provider with API key support (inline or via file)
- Prompt customization and input property selection
- Two regression tests: basic and invalid-key scenarios
- Sphinx documentation under `doc/configuration/modules`

Note: mmaitag is in its infancy and primarily a PoC. Future work
will improve batching, performance, and add more providers.

Refs:
- https://github.com/rsyslog/rsyslog/issues/5747 (AI-first strategy)

With the help of AI Agents: Codex, Gemini
2025-07-15 17:33:07 +02:00
Rainer Gerhards
3a1024379c
Merge pull request #5596 from rgerhards/coverity-imptcp
imptcp bugfix: potential socket leak
2025-07-15 17:01:34 +02:00
Rainer Gerhards
fbbd523a72
Merge pull request #5782 from rgerhards/impstats-prometheus
impstats: add support for Prometheus metrics output format
2025-07-15 14:02:52 +02:00
Rainer Gerhards
fe4ac615aa
Merge pull request #5665 from rsyslog/codex/evaluate-adding-pcre-matches-to-rsyslog
Add optional PCRE match function
2025-07-15 13:08:30 +02:00
Rainer Gerhards
63c7e7d67d impstats: add support for Prometheus metrics output format
This commit extends the impstats input module to support a new
"prometheus" format for exporting statistics. The output is
generated via statsobj.c, which already provides Prometheus-
compatible formatting.

To enable this, a new "format" config option value ("prometheus")
was added and recognized by impstats.c. When selected, impstats
invokes the appropriate statsobj function to generate output in
Prometheus exposition format.

The default behavior remains unchanged. Existing formats such as
"json" and "legacy" are not modified.

A new test has been added under tests/ to validate correct
Prometheus output generation. The test verifies that the format
header and at least one representative metric line conform to the
Prometheus text format specification.

This enhancement enables rsyslog to integrate more easily with
Prometheus-based monitoring stacks and paves the way for native
metrics scraping without external translation layers.
2025-07-15 12:29:06 +02:00
Rainer Gerhards
249a2d1228
Merge pull request #5744 from Cropi/imfile-state-file-fix
Introduce new imfile module parameter: deleteStateOnFileMove
2025-07-15 12:21:37 +02:00
Cropi
0f5dbad19e imfile: add new module/input parameter deleteStateOnFileMove
When enabled, state files are deleted when the watched file is moved or
rotated away.  This prevents accumulation of stale state files from
rotated logs.  By default the state file is kept. Does not change
default behavior for existing inputs.  The config option is available as
per-input and per-module parameter.
2025-07-15 10:03:42 +02:00
Rainer Gerhards
7225999b77 refactor: modernize macro definitions to support formatting and clarity
This commit performs a broad modernization of widely used rsyslog
macros to align with modern C practices and support automated
formatting tools like clang-format. The changes focus on improving
syntactic regularity, readability, and tooling compatibility — without
altering behavior.

Macros refactored in this commit now follow a consistent,
statement-like form with explicit trailing semicolons. Where
applicable, macro blocks that define module interfaces (`queryEtryPt`)
have been updated to use simple `if` statements instead of `else if`
chains. While this slightly increases evaluation time, the affected
functions are only called once per module during load time to register
supported interfaces — making the performance cost irrelevant in
practice.

These improvements serve multiple purposes:
- Enable reliable clang-format usage without mangling macro logic
- Simplify reasoning about macro-expanded code for human readers
- Reduce style drift and merge conflicts
- Facilitate development for contributors using assistive tools
- Support future formatting pipelines using:
  1. `clang-format`
  2. a post-fixup normalization script

Refactored macros:
- MODULE_TYPE_NOKEEP
- MODULE_TYPE_KEEP
- MODULE_TYPE_INPUT
- MODULE_TYPE_OUTPUT
- MODULE_TYPE_FUNCTION
- MODULE_TYPE_PARSER
- MODULE_TYPE_LIB
- DEF_IMOD_STATIC_DATA
- DEF_OMOD_STATIC_DATA
- DEF_PMOD_STATIC_DATA
- DEF_FMOD_STATIC_DATA
- DEFobjStaticHelpers
- SIMP_PROP(...)

And all `queryEtryPt()` dispatch macros:
- CODEqueryEtryPt_STD_MOD_QUERIES
- CODEqueryEtryPt_STD_OMOD_QUERIES
- CODEqueryEtryPt_STD_OMODTX_QUERIES
- CODEqueryEtryPt_STD_OMOD8_QUERIES
- CODEqueryEtryPt_TXIF_OMOD_QUERIES
- CODEqueryEtryPt_IsCompatibleWithFeature_IF_OMOD_QUERIES
- CODEqueryEtryPt_STD_IMOD_QUERIES
- CODEqueryEtryPt_STD_CONF2_QUERIES
- CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES
- CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES
- CODEqueryEtryPt_STD_CONF2_IMOD_QUERIES
- CODEqueryEtryPt_STD_CONF2_PREPRIVDROP_QUERIES
- CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES
- CODEqueryEtryPt_STD_PMOD_QUERIES
- CODEqueryEtryPt_STD_PMOD2_QUERIES
- CODEqueryEtryPt_STD_FMOD_QUERIES
- CODEqueryEtryPt_STD_SMOD_QUERIES
- CODEqueryEtryPt_doHUPWrkr
- CODEqueryEtryPt_doHUP

This general modernization reduces macro misuse, improves DX, and
lays the foundation for a robust, automated style normalization
system.

See also: https://github.com/rsyslog/rsyslog/issues/5747
2025-07-15 08:25:58 +02:00
Rainer Gerhards
e109e0a7d5
Add optional PCRE match module 2025-07-11 17:08:26 +02:00
Rainer Gerhards
e20cfc83d9
Fix unsafe sprintf use in Azure event hubs module (#5687)
* use snprintf for url encoding

With the help of AI-Agent: Codex 2025-06
2025-07-11 16:09:12 +02:00
Rainer Gerhards
0fc3bb05ec
Document native message modification plugin interface (#5757)
* doc: document native mm interface
2025-07-08 12:57:40 +02:00
Rainer Gerhards
50e4a06b18
helper utils: clean up python indentation
* Add note for indentation cleanup
* Converted tabs to spaces in various Python scripts to match PEP 8 indentation.

With the help of AI-Agent: Codex, Google Gemini Code review
2025-07-05 14:34:43 +02:00
Rainer Gerhards
bfdce6ab2f
imfile: some cleanup, no functional changes
- removed commented out code
- clarified and unified a configuration parameter alias
  Note: both need to stay for backwards-compatibility
2025-06-20 17:58:15 +02:00
Rainer Gerhards
5af4f668b1
omsendertrack fix: memory leak in initHashTable 2025-06-17 18:05:08 +02:00
Rainer Gerhards
c86976482d
more manually curated changes
Also now includes pblk parameter description comments. This is
a prototype. We will use this method later to generate user
reference doc.
2025-06-15 15:41:34 +02:00
Rainer Gerhards
903be21b2b
manually curated changes to the AI agent generated code 2025-06-15 10:40:28 +02:00
Rainer Gerhards
c25977a4c3 docs: document proof-of-concept status 2025-06-15 10:30:42 +02:00
Rainer Gerhards
e7dfcc9a74
cleanup and doc improvement
among others, remove some warning suppressions by "fixing" the
respective constructs with work-arounds (root cause is compilers
do not handle enums in switch well).
2025-06-14 14:38:51 +02:00
Attila Lakatos
9b6525b1d2
ossl netstream driver: do not import engines if not available (#5685)
Avoid including openssl/engine.h when OPENSSL_NO_ENGINE is set. Adjust dependent modules and test accordingly.
2025-06-12 19:23:50 +02:00
Cropi
90e0971b4b Removed the redundant *_la_LDFLAGS
Whilst this did not cause issues when building the project, it produced
warnings.
2025-06-12 10:46:19 +02:00
Rainer Gerhards
9f7f1815bb
CI: new python-based codestyle checker
Easier to maintain than the off-project C source. The checks
are pretty trivial.

This also fixes some nits that the old checker did not detect.

closes https://github.com/rsyslog/rsyslog/issues/5631
2025-06-09 18:43:36 +02:00
Rainer Gerhards
d6d340aaad
omfwd regression fix: avoid false active target change log message
Commit ffaf6dc4620da added proper variable sync, but dropped the check
if active count had actually changed. As such, the output was always
generated, which could pollute the log heavily.

also fixes some codestyle issues introduced by earlier commits.

With the help of AI-Agent: Codex 2025-06
2025-06-09 17:41:52 +02:00
Rainer Gerhards
f0372aa8b3
Merge pull request #5606 from Cropi/imjournal-dicarded
imuxsock: Add statistics counter for discarded messages
2025-06-09 13:58:54 +02:00
Rainer Gerhards
ab5d2c7ab6
Merge pull request #5446 from infracaninophile/freebsd-compat-fixes
Add header includes to support compilation on FreeBSD
2025-06-08 08:53:36 +02:00
Rainer Gerhards
1c6d6a9079
Merge pull request #5656 from rgerhards/codex/fehler-in-einem-relevanten-codeabschnitt-beheben
fix mime type typo
2025-06-08 08:17:20 +02:00
Rainer Gerhards
272877c662 fix mime type typo 2025-06-05 13:05:20 +02:00
Rainer Gerhards
afd91282e7
stats: add prometheus format to set of supported output formats 2025-06-04 18:49:32 +02:00
Rainer Gerhards
9016f1f1b3
omsendertrack: new module
The omsendertrack module is designed to track and report statistics for
message senders across all inputs in Rsyslog. It periodically outputs a
JSON file containing information about each sender.

Note: This commit provides minimalistic basic functionality as a PoC.
We will check it's usefulness in practice and expect follow-up PRs
to enhance functionality and include feedback from early testing.

However, this module is solid, just feature limited.

see also: https://github.com/rsyslog/rsyslog/issues/5599
2025-06-04 08:42:12 +02:00
Rainer Gerhards
e6c009f764
Merge pull request #5608 from anis-bougrine/fix-omjournal-priority-value
omjournal: Fix priority value.
2025-05-29 08:58:05 +02:00
28c4a15845 imudp: Output errno after recvmmsg call
closes https://github.com/rsyslog/rsyslog/issues/5646
2025-05-23 08:35:53 +02:00