]> granicus.if.org Git - strace/commitdiff
syslog: decode log level in SYSLOG_ACTION_CONSOLE_LEVEL command
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 27 Sep 2018 05:17:27 +0000 (07:17 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 5 Aug 2019 22:48:31 +0000 (22:48 +0000)
* 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.

syslog.c
tests/syslog.c
xlat/syslog_console_levels.in [new file with mode: 0644]

index 1297f7f142e5170f92c9265b0f07976333a48154..b5e0d8f342956ac4d5e6323b0c62a7f1ef27d529 100644 (file)
--- a/syslog.c
+++ b/syslog.c
@@ -9,6 +9,7 @@
 #include "defs.h"
 
 #include "xlat/syslog_action_type.h"
+#include "xlat/syslog_console_levels.h"
 
 SYS_FUNC(syslog)
 {
@@ -40,6 +41,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]);
index a3c66e8d7e96cccaf0b62ad8261ea0f444ba2cdd..a3417ea210716cc42cf2a8238f959fdc63740f51 100644 (file)
@@ -58,6 +58,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;
@@ -90,6 +99,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;
 }
diff --git a/xlat/syslog_console_levels.in b/xlat/syslog_console_levels.in
new file mode 100644 (file)
index 0000000..9309658
--- /dev/null
@@ -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