diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 11:57:52 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 11:57:52 +0100 |
| commit | 48a9df043df64887cb99e03d7613379c947d11d8 (patch) | |
| tree | 897d94bcc55c481a82878c5d2de5ec3369df33ed /src/server_lds.c | |
| parent | a54421dd976fd8081e96c11c2621076876c9986b (diff) | |
| download | BobinkCOpcUa-48a9df043df64887cb99e03d7613379c947d11d8.tar.gz BobinkCOpcUa-48a9df043df64887cb99e03d7613379c947d11d8.zip | |
Add configurable log level as optional CLI argument
All three programs now accept an optional second argument [log-level]
(trace, debug, info, warning, error, fatal) defaulting to info. The
level is applied by setting the logger context pointer directly,
avoiding a memory leak that would occur from overwriting the
heap-allocated logger struct. Also documents the ASan leak-check
workflow in CLAUDE.md.
Diffstat (limited to 'src/server_lds.c')
| -rw-r--r-- | src/server_lds.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/server_lds.c b/src/server_lds.c index c6960d5..2fe508f 100644 --- a/src/server_lds.c +++ b/src/server_lds.c @@ -35,10 +35,21 @@ main (int argc, char *argv[]) signal (SIGINT, stopHandler); signal (SIGTERM, stopHandler); - if (argc != 2) + if (argc < 2 || argc > 3) { UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, - "Usage: %s <config-file>", argv[0]); + "Usage: %s <config-file> [log-level]", argv[0]); + return EXIT_FAILURE; + } + + const char *logLevelStr = (argc == 3) ? argv[2] : "info"; + int logLevel = parseLogLevel (logLevelStr); + if (logLevel < 0) + { + UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, + "Unknown log level: %s " + "(expected trace, debug, info, warning, error, fatal)", + logLevelStr); return EXIT_FAILURE; } @@ -116,6 +127,12 @@ main (int argc, char *argv[]) } UA_ServerConfig *serverConfig = UA_Server_getConfig (server); + serverConfig->logging->context = (void *)(uintptr_t)logLevel; + + /* Some OPC UA stacks omit the timestamp in the request header. The + default behaviour rejects these requests with BadInvalidTimestamp. + Downgrade to a warning so third-party servers can still register. */ + serverConfig->verifyRequestTimestamp = UA_RULEHANDLING_WARN; /* Configure access control after server creation because UA_ServerConfig_setDefaultWithSecurityPolicies (called by |
