Repository navigation
lib/log.c: accept arrays of names and use the documented defaults - #460
Merged
Merged
Conversation
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>
Collaborator
|
Merged, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.