Merge pull request #11882 from yuwata/fix-log-syntax

Fix log_syntax()
This commit is contained in:
Lennart Poettering 2019-03-04 11:03:36 +01:00 committed by GitHub
commit 965bfcd6b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View file

@ -1223,7 +1223,7 @@ int log_syntax_internal(
log_target == LOG_TARGET_NULL)
return -ERRNO_VALUE(error);
errno = error;
errno = ERRNO_VALUE(error);
va_start(ap, format);
(void) vsnprintf(buffer, sizeof buffer, format, ap);

View file

@ -308,7 +308,7 @@ int log_syntax_invalid_utf8_internal(
int _level = (level), _e = (error); \
(log_get_max_level() >= LOG_PRI(_level)) \
? log_syntax_internal(unit, _level, config_file, config_line, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \
: -abs(_e); \
: -ERRNO_VALUE(_e); \
})
#define log_syntax_invalid_utf8(unit, level, config_file, config_line, rvalue) \

View file

@ -59,15 +59,22 @@ static void test_long_lines(void) {
"asdfasdf %s asdfasdfa", "foobar");
}
static void test_log_syntax(void) {
assert_se(log_syntax("unit", LOG_ERR, "filename", 10, EINVAL, "EINVAL: %s: %m", "hogehoge") == -EINVAL);
assert_se(log_syntax("unit", LOG_ERR, "filename", 10, -ENOENT, "ENOENT: %s: %m", "hogehoge") == -ENOENT);
assert_se(log_syntax("unit", LOG_ERR, "filename", 10, SYNTHETIC_ERRNO(ENOTTY), "ENOTTY: %s: %m", "hogehoge") == -ENOTTY);
}
int main(int argc, char* argv[]) {
int target;
for (target = 0; target < _LOG_TARGET_MAX; target++) {
for (target = 0; target < _LOG_TARGET_MAX; target++) {
log_set_target(target);
log_open();
test_log_struct();
test_long_lines();
test_log_syntax();
}
assert_se(log_info_errno(SYNTHETIC_ERRNO(EUCLEAN), "foo") == -EUCLEAN);