Skip to content

lib/log.c: accept arrays of names and use the documented defaults - #460

Merged
jow- merged 2 commits into
ucode-lang:masterfrom
strrs:log-args
Oct 2, 2026
Merged

jow- merged 2 commits into
ucode-lang:masterfrom
strrs:log-args

Conversation

@strrs

@strrs strrs commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

ulog_open() and openlog() return false for any non-empty array of channel or option names, including the jsdoc examples. The parsers take an omitted channel or facility as 0, so ulog_open() without a channel logs nothing, and both functions without a facility log as LOG_KERN instead of the documented defaults.

The first commit fixes the array loops in parse_channels() and parse_options() and adds tests in a new 07_lib_log category. The ulog test needs log.so built with libubox and fails without it. The second commit passes -1 to libubox and LOG_USER to openlog() instead of 0 for an omitted channel or facility. Callers that omit the facility move from kern to daemon or user, and ulog_open() without a channel now logs to the channel libubox picks. In OpenWrt, LuCI's dispatcher.uc and http.uc call openlog() with an ident only, so the warnings they log without a facility arrive as kern.warning today.

Tested on a glibc build of master: the new tests fail without the first commit and pass with it, the custom suite passes under valgrind, and calls that omit the facility log as daemon.info and user.info. On OpenWrt main (ucode b885dd0, musl) the array calls return false and the messages without a facility arrive as kern.info. Both patches apply there unchanged.

strrs added 2 commits October 2, 2026 06:41
ulog_open() and openlog() return false for every non-empty array of
channel or option names, including the jsdoc examples
ulog_open(["stdio", "kmsg"], ...) and
openlog("myapp", [ "pid", "ndelay" ], "user"). The array loops in
parse_channels() and parse_options() return an error at the first table
entry an element does not match.

Look the element up in the table and fail only when no entry matches. A
non-string element still fails and an empty array still yields no flags.

Add tests for both functions in a new 07_lib_log category. The ulog test
needs the module built with libubox.

Signed-off-by: Semih Baskan <strst.gs@gmail.com>
ulog_open() with the channel argument omitted configures no channel, so
ulog() drops every later message. ulog_open() or openlog() with the
facility omitted logs with facility 0, LOG_KERN. Both come from
parse_channels() and parse_facility() returning 0 for a null argument.
The jsdoc gives the libubox context defaults for ulog_open() and "user"
for openlog().

Check for the omitted argument at the call site, as lib/socket.c and
lib/ubus.c do for an omitted timeout. Pass -1 to libubox for an omitted
channel or facility, so that it picks its defaults, and LOG_USER to
openlog() for an omitted facility. An omitted options argument stays 0,
since no option is the right default there.

Callers that omit the facility log under kern today. With this change
they move to user for openlog(), and to daemon or user for ulog_open(),
whichever libubox selects for the context. ulog_open() without a
channel, which logged nothing, now logs to the channel libubox picks.

Signed-off-by: Semih Baskan <strst.gs@gmail.com>
@jow-
jow- merged commit aabb949 into ucode-lang:master Oct 2, 2026
2 checks passed
@jow-

jow- commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Merged, thanks!

@strrs
strrs deleted the log-args branch October 2, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants