Browse Source

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.
Eugene Syromyatnikov 1 year ago
parent
commit
489690a120
3 changed files with 37 additions and 0 deletions
  1. 10
    0
      syslog.c
  2. 16
    0
      tests/syslog.c
  3. 11
    0
      xlat/syslog_console_levels.in

+ 10
- 0
syslog.c View File

@@ -9,6 +9,7 @@
9 9
 #include "defs.h"
10 10
 
11 11
 #include "xlat/syslog_action_type.h"
12
+#include "xlat/syslog_console_levels.h"
12 13
 
13 14
 SYS_FUNC(syslog)
14 15
 {
@@ -40,6 +41,15 @@ SYS_FUNC(syslog)
40 41
 			return 0;
41 42
 		}
42 43
 		break;
44
+
45
+	case SYSLOG_ACTION_CONSOLE_LEVEL: /* Uses len */
46
+		tprints(", ");
47
+		printaddr64(tcp->u_arg[1]);
48
+		tprints(", ");
49
+		printxval_ex(syslog_console_levels, len, "LOGLEVEL_???",
50
+			     XLAT_STYLE_VERBOSE | XLAT_STYLE_FMT_D);
51
+		return RVAL_DECODED;
52
+
43 53
 	default:
44 54
 		tprints(", ");
45 55
 		printaddr64(tcp->u_arg[1]);

+ 16
- 0
tests/syslog.c View File

@@ -58,6 +58,15 @@ main(void)
58 58
 		{ 11, "11 /* SYSLOG_ACTION_??? */" },
59 59
 		{ (1U << 31) - 1, "2147483647 /* SYSLOG_ACTION_??? */" },
60 60
 	};
61
+	static const struct cmd_str levels[] = {
62
+		{ 0xfeedbeef, "-17973521 /* LOGLEVEL_??? */" },
63
+		{ -1U, "-1 /* LOGLEVEL_??? */" },
64
+		{ 0, "0 /* LOGLEVEL_EMERG */" },
65
+		{ 7, "7 /* LOGLEVEL_DEBUG */" },
66
+		{ 8, "8 /* LOGLEVEL_DEBUG+1 */" },
67
+		{ 9, "9 /* LOGLEVEL_??? */" },
68
+		{ (1U << 31) - 1, "2147483647 /* LOGLEVEL_??? */" },
69
+	};
61 70
 	static const kernel_ulong_t high =
62 71
 		(kernel_ulong_t) 0xbadc0ded00000000ULL;
63 72
 	const kernel_ulong_t addr = (kernel_ulong_t) 0xfacefeeddeadbeefULL;
@@ -90,6 +99,13 @@ main(void)
90 99
 		       sprintrc(rc));
91 100
 	}
92 101
 
102
+	for (size_t i = 0; i < ARRAY_SIZE(levels); i++) {
103
+		rc = syscall(__NR_syslog, high | 8, addr, levels[i].cmd);
104
+		printf("syslog(8 /* SYSLOG_ACTION_CONSOLE_LEVEL */, %#llx, %s)"
105
+		       " = %s\n",
106
+		       (unsigned long long) addr, levels[i].str, sprintrc(rc));
107
+	}
108
+
93 109
 	puts("+++ exited with 0 +++");
94 110
 	return 0;
95 111
 }

+ 11
- 0
xlat/syslog_console_levels.in View File

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

Loading…
Cancel
Save