dmesg: allow specification of level range
This commit is contained in:
parent
0cd9d2993d
commit
73a96af6ec
6 changed files with 185 additions and 5 deletions
|
@ -211,7 +211,8 @@ extern int string_add_to_idarray(const char *list, int ary[],
|
||||||
int (name2id)(const char *, size_t));
|
int (name2id)(const char *, size_t));
|
||||||
|
|
||||||
extern int string_to_bitarray(const char *list, char *ary,
|
extern int string_to_bitarray(const char *list, char *ary,
|
||||||
int (*name2bit)(const char *, size_t));
|
int (*name2bit)(const char *, size_t),
|
||||||
|
size_t allow_range);
|
||||||
|
|
||||||
extern int string_to_bitmask(const char *list,
|
extern int string_to_bitmask(const char *list,
|
||||||
unsigned long *mask,
|
unsigned long *mask,
|
||||||
|
|
|
@ -724,11 +724,16 @@ int string_add_to_idarray(const char *list, int ary[], size_t arysz,
|
||||||
* as a position in the 'ary' bit array. It means that the 'id' has to be in
|
* as a position in the 'ary' bit array. It means that the 'id' has to be in
|
||||||
* range <0..N> where N < sizeof(ary) * NBBY.
|
* range <0..N> where N < sizeof(ary) * NBBY.
|
||||||
*
|
*
|
||||||
|
* If allow_range is enabled:
|
||||||
|
* An item ending in '+' also sets all bits in <0..N>.
|
||||||
|
* An item beginning with '+' also sets all bits in <N..allow_minus>.
|
||||||
|
*
|
||||||
* Returns: 0 on success, <0 on error.
|
* Returns: 0 on success, <0 on error.
|
||||||
*/
|
*/
|
||||||
int string_to_bitarray(const char *list,
|
int string_to_bitarray(const char *list,
|
||||||
char *ary,
|
char *ary,
|
||||||
int (*name2bit)(const char *, size_t))
|
int (*name2bit)(const char *, size_t),
|
||||||
|
size_t allow_range)
|
||||||
{
|
{
|
||||||
const char *begin = NULL, *p;
|
const char *begin = NULL, *p;
|
||||||
|
|
||||||
|
@ -737,7 +742,7 @@ int string_to_bitarray(const char *list,
|
||||||
|
|
||||||
for (p = list; p && *p; p++) {
|
for (p = list; p && *p; p++) {
|
||||||
const char *end = NULL;
|
const char *end = NULL;
|
||||||
int bit;
|
int bit, set_lower = 0, set_higher = 0;
|
||||||
|
|
||||||
if (!begin)
|
if (!begin)
|
||||||
begin = p; /* begin of the level name */
|
begin = p; /* begin of the level name */
|
||||||
|
@ -749,11 +754,26 @@ int string_to_bitarray(const char *list,
|
||||||
continue;
|
continue;
|
||||||
if (end <= begin)
|
if (end <= begin)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (allow_range) {
|
||||||
|
if (*(end - 1) == '+') {
|
||||||
|
end--;
|
||||||
|
set_lower = 1;
|
||||||
|
} else if (*begin == '+') {
|
||||||
|
begin++;
|
||||||
|
set_higher = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bit = name2bit(begin, end - begin);
|
bit = name2bit(begin, end - begin);
|
||||||
if (bit < 0)
|
if (bit < 0)
|
||||||
return bit;
|
return bit;
|
||||||
setbit(ary, bit);
|
setbit(ary, bit);
|
||||||
|
if (set_lower)
|
||||||
|
while (--bit >= 0)
|
||||||
|
setbit(ary, bit);
|
||||||
|
else if (set_higher)
|
||||||
|
while (++bit < (int) allow_range)
|
||||||
|
setbit(ary, bit);
|
||||||
begin = NULL;
|
begin = NULL;
|
||||||
if (end && !*end)
|
if (end && !*end)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -84,6 +84,14 @@ Restrict output to the given (comma-separated) _list_ of levels. For example:
|
||||||
*dmesg --level=err,warn*
|
*dmesg --level=err,warn*
|
||||||
+
|
+
|
||||||
will print error and warning messages only. For all supported levels see the *--help* output.
|
will print error and warning messages only. For all supported levels see the *--help* output.
|
||||||
|
+
|
||||||
|
Appending a plus *+* to a level name also includes all higher levels. For example:
|
||||||
|
+
|
||||||
|
*dmesg --level=err+*
|
||||||
|
+
|
||||||
|
will print levels *err*, *crit*, *alert* and *emerg*.
|
||||||
|
+
|
||||||
|
Prepending it will include all lower levels.
|
||||||
|
|
||||||
*-n*, *--console-level* _level_::
|
*-n*, *--console-level* _level_::
|
||||||
Set the _level_ at which printing of messages is done to the console. The _level_ is a level number or abbreviation of the level name. For all supported levels see the *--help* output.
|
Set the _level_ at which printing of messages is done to the console. The _level_ is a level number or abbreviation of the level name. For all supported levels see the *--help* output.
|
||||||
|
|
|
@ -1475,7 +1475,7 @@ int main(int argc, char *argv[])
|
||||||
case 'f':
|
case 'f':
|
||||||
ctl.fltr_fac = 1;
|
ctl.fltr_fac = 1;
|
||||||
if (string_to_bitarray(optarg,
|
if (string_to_bitarray(optarg,
|
||||||
ctl.facilities, parse_facility) < 0)
|
ctl.facilities, parse_facility, 0) < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
|
@ -1499,7 +1499,8 @@ int main(int argc, char *argv[])
|
||||||
case 'l':
|
case 'l':
|
||||||
ctl.fltr_lev= 1;
|
ctl.fltr_lev= 1;
|
||||||
if (string_to_bitarray(optarg,
|
if (string_to_bitarray(optarg,
|
||||||
ctl.levels, parse_level) < 0)
|
ctl.levels, parse_level,
|
||||||
|
ARRAY_SIZE(level_names)) < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
|
|
|
@ -102,3 +102,147 @@
|
||||||
[658503.000000] example[87]
|
[658503.000000] example[87]
|
||||||
[857375.000000] example[95]
|
[857375.000000] example[95]
|
||||||
[1092727.000000] example[103]
|
[1092727.000000] example[103]
|
||||||
|
[ 0.000000] example[0]
|
||||||
|
[ 1.000000] example[1]
|
||||||
|
[ 8.000000] example[2]
|
||||||
|
[ 27.000000] example[3]
|
||||||
|
[ 512.000000] example[8]
|
||||||
|
[ 729.000000] example[9]
|
||||||
|
[ 1000.000000] example[10]
|
||||||
|
[ 1331.000000] example[11]
|
||||||
|
[ 4096.000000] example[16]
|
||||||
|
[ 4913.000000] example[17]
|
||||||
|
[ 5832.000000] example[18]
|
||||||
|
[ 6859.000000] example[19]
|
||||||
|
[13824.000000] example[24]
|
||||||
|
[15625.000000] example[25]
|
||||||
|
[17576.000000] example[26]
|
||||||
|
[19683.000000] example[27]
|
||||||
|
[32768.000000] example[32]
|
||||||
|
[35937.000000] example[33]
|
||||||
|
[39304.000000] example[34]
|
||||||
|
[42875.000000] example[35]
|
||||||
|
[64000.000000] example[40]
|
||||||
|
[68921.000000] example[41]
|
||||||
|
[74088.000000] example[42]
|
||||||
|
[79507.000000] example[43]
|
||||||
|
[110592.000000] example[48]
|
||||||
|
[117649.000000] example[49]
|
||||||
|
[125000.000000] example[50]
|
||||||
|
[132651.000000] example[51]
|
||||||
|
[175616.000000] example[56]
|
||||||
|
[185193.000000] example[57]
|
||||||
|
[195112.000000] example[58]
|
||||||
|
[205379.000000] example[59]
|
||||||
|
[262144.000000] example[64]
|
||||||
|
[274625.000000] example[65]
|
||||||
|
[287496.000000] example[66]
|
||||||
|
[300763.000000] example[67]
|
||||||
|
[373248.000000] example[72]
|
||||||
|
[389017.000000] example[73]
|
||||||
|
[405224.000000] example[74]
|
||||||
|
[421875.000000] example[75]
|
||||||
|
[512000.000000] example[80]
|
||||||
|
[531441.000000] example[81]
|
||||||
|
[551368.000000] example[82]
|
||||||
|
[571787.000000] example[83]
|
||||||
|
[681472.000000] example[88]
|
||||||
|
[704969.000000] example[89]
|
||||||
|
[729000.000000] example[90]
|
||||||
|
[753571.000000] example[91]
|
||||||
|
[884736.000000] example[96]
|
||||||
|
[912673.000000] example[97]
|
||||||
|
[941192.000000] example[98]
|
||||||
|
[970299.000000] example[99]
|
||||||
|
[ 0.000000] example[0]
|
||||||
|
[ 512.000000] example[8]
|
||||||
|
[ 4096.000000] example[16]
|
||||||
|
[13824.000000] example[24]
|
||||||
|
[32768.000000] example[32]
|
||||||
|
[64000.000000] example[40]
|
||||||
|
[110592.000000] example[48]
|
||||||
|
[175616.000000] example[56]
|
||||||
|
[262144.000000] example[64]
|
||||||
|
[373248.000000] example[72]
|
||||||
|
[512000.000000] example[80]
|
||||||
|
[681472.000000] example[88]
|
||||||
|
[884736.000000] example[96]
|
||||||
|
[ 27.000000] example[3]
|
||||||
|
[ 64.000000] example[4]
|
||||||
|
[ 125.000000] example[5]
|
||||||
|
[ 216.000000] example[6]
|
||||||
|
[ 343.000000] example[7]
|
||||||
|
[ 1331.000000] example[11]
|
||||||
|
[ 1728.000000] example[12]
|
||||||
|
[ 2197.000000] example[13]
|
||||||
|
[ 2744.000000] example[14]
|
||||||
|
[ 3375.000000] example[15]
|
||||||
|
[ 6859.000000] example[19]
|
||||||
|
[ 8000.000000] example[20]
|
||||||
|
[ 9261.000000] example[21]
|
||||||
|
[10648.000000] example[22]
|
||||||
|
[12167.000000] example[23]
|
||||||
|
[19683.000000] example[27]
|
||||||
|
[21952.000000] example[28]
|
||||||
|
[24389.000000] example[29]
|
||||||
|
[27000.000000] example[30]
|
||||||
|
[29791.000000] example[31]
|
||||||
|
[42875.000000] example[35]
|
||||||
|
[46656.000000] example[36]
|
||||||
|
[50653.000000] example[37]
|
||||||
|
[54872.000000] example[38]
|
||||||
|
[59319.000000] example[39]
|
||||||
|
[79507.000000] example[43]
|
||||||
|
[85184.000000] example[44]
|
||||||
|
[91125.000000] example[45]
|
||||||
|
[97336.000000] example[46]
|
||||||
|
[103823.000000] example[47]
|
||||||
|
[132651.000000] example[51]
|
||||||
|
[140608.000000] example[52]
|
||||||
|
[148877.000000] example[53]
|
||||||
|
[157464.000000] example[54]
|
||||||
|
[166375.000000] example[55]
|
||||||
|
[205379.000000] example[59]
|
||||||
|
[216000.000000] example[60]
|
||||||
|
[226981.000000] example[61]
|
||||||
|
[238328.000000] example[62]
|
||||||
|
[250047.000000] example[63]
|
||||||
|
[300763.000000] example[67]
|
||||||
|
[314432.000000] example[68]
|
||||||
|
[328509.000000] example[69]
|
||||||
|
[343000.000000] example[70]
|
||||||
|
[357911.000000] example[71]
|
||||||
|
[421875.000000] example[75]
|
||||||
|
[438976.000000] example[76]
|
||||||
|
[456533.000000] example[77]
|
||||||
|
[474552.000000] example[78]
|
||||||
|
[493039.000000] example[79]
|
||||||
|
[571787.000000] example[83]
|
||||||
|
[592704.000000] example[84]
|
||||||
|
[614125.000000] example[85]
|
||||||
|
[636056.000000] example[86]
|
||||||
|
[658503.000000] example[87]
|
||||||
|
[753571.000000] example[91]
|
||||||
|
[778688.000000] example[92]
|
||||||
|
[804357.000000] example[93]
|
||||||
|
[830584.000000] example[94]
|
||||||
|
[857375.000000] example[95]
|
||||||
|
[970299.000000] example[99]
|
||||||
|
[1000000.000000] example[100]
|
||||||
|
[1030301.000000] example[101]
|
||||||
|
[1061208.000000] example[102]
|
||||||
|
[1092727.000000] example[103]
|
||||||
|
[ 343.000000] example[7]
|
||||||
|
[ 3375.000000] example[15]
|
||||||
|
[12167.000000] example[23]
|
||||||
|
[29791.000000] example[31]
|
||||||
|
[59319.000000] example[39]
|
||||||
|
[103823.000000] example[47]
|
||||||
|
[166375.000000] example[55]
|
||||||
|
[250047.000000] example[63]
|
||||||
|
[357911.000000] example[71]
|
||||||
|
[493039.000000] example[79]
|
||||||
|
[658503.000000] example[87]
|
||||||
|
[857375.000000] example[95]
|
||||||
|
[1092727.000000] example[103]
|
||||||
|
test_dmesg: unknown level '+'
|
||||||
|
|
|
@ -27,4 +27,10 @@ for I in {-1..8}; do
|
||||||
$TS_HELPER_DMESG -F $TS_SELF/input -l $I >> $TS_OUTPUT 2>/dev/null
|
$TS_HELPER_DMESG -F $TS_SELF/input -l $I >> $TS_OUTPUT 2>/dev/null
|
||||||
done
|
done
|
||||||
|
|
||||||
|
$TS_HELPER_DMESG -F $TS_SELF/input -l err+ >> $TS_OUTPUT 2>/dev/null
|
||||||
|
$TS_HELPER_DMESG -F $TS_SELF/input -l emerg+ >> $TS_OUTPUT 2>/dev/null
|
||||||
|
$TS_HELPER_DMESG -F $TS_SELF/input -l +err >> $TS_OUTPUT 2>/dev/null
|
||||||
|
$TS_HELPER_DMESG -F $TS_SELF/input -l +debug >> $TS_OUTPUT 2>/dev/null
|
||||||
|
$TS_HELPER_DMESG -F $TS_SELF/input -l + 2>> $TS_OUTPUT >/dev/null
|
||||||
|
|
||||||
ts_finalize
|
ts_finalize
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue