syslog: decode log level in SYSLOG_ACTION_CONSOLE_LEVEL command

* xlat/syslog_console_levels.in: New file.
* syslog.c: Include "xlat/syslog_console_levels.h".
(SYS_FUNC(syslog)): Add SYSLOG_ACTION_CONSOLE_LEVEL case.
* tests/syslog.c: Add checks.
This commit is contained in:
Eugene Syromyatnikov 2018-09-27 07:17:27 +02:00
parent 9ea764c377
commit a26ad5c9ad
3 changed files with 37 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include "defs.h"
#include "xlat/syslog_action_type.h"
#include "xlat/syslog_console_levels.h"
SYS_FUNC(syslog)
{
@ -60,6 +61,15 @@ SYS_FUNC(syslog)
return 0;
}
break;
case SYSLOG_ACTION_CONSOLE_LEVEL: /* Uses len */
tprints(", ");
printaddr64(tcp->u_arg[1]);
tprints(", ");
printxval_ex(syslog_console_levels, len, "LOGLEVEL_???",
XLAT_STYLE_VERBOSE | XLAT_STYLE_FMT_D);
return RVAL_DECODED;
default:
tprints(", ");
printaddr64(tcp->u_arg[1]);

View File

@ -52,6 +52,15 @@ main(void)
{ 11, "11 /* SYSLOG_ACTION_??? */" },
{ (1U << 31) - 1, "2147483647 /* SYSLOG_ACTION_??? */" },
};
static const struct cmd_str levels[] = {
{ 0xfeedbeef, "-17973521 /* LOGLEVEL_??? */" },
{ -1U, "-1 /* LOGLEVEL_??? */" },
{ 0, "0 /* LOGLEVEL_EMERG */" },
{ 7, "7 /* LOGLEVEL_DEBUG */" },
{ 8, "8 /* LOGLEVEL_DEBUG+1 */" },
{ 9, "9 /* LOGLEVEL_??? */" },
{ (1U << 31) - 1, "2147483647 /* LOGLEVEL_??? */" },
};
static const kernel_ulong_t high =
(kernel_ulong_t) 0xbadc0ded00000000ULL;
const kernel_ulong_t addr = (kernel_ulong_t) 0xfacefeeddeadbeefULL;
@ -84,6 +93,13 @@ main(void)
sprintrc(rc));
}
for (size_t i = 0; i < ARRAY_SIZE(levels); i++) {
rc = syscall(__NR_syslog, high | 8, addr, levels[i].cmd);
printf("syslog(8 /* SYSLOG_ACTION_CONSOLE_LEVEL */, %#llx, %s)"
" = %s\n",
(unsigned long long) addr, levels[i].str, sprintrc(rc));
}
puts("+++ exited with 0 +++");
return 0;
}

View File

@ -0,0 +1,11 @@
#value_indexed
/* from include/linux/kern_levels.h */
LOGLEVEL_EMERG 0
LOGLEVEL_ALERT 1
LOGLEVEL_CRIT 2
LOGLEVEL_ERR 3
LOGLEVEL_WARNING 4
LOGLEVEL_NOTICE 5
LOGLEVEL_INFO 6
LOGLEVEL_DEBUG 7
LOGLEVEL_DEBUG+1 7