]> git.ipfire.org Git - thirdparty/systemd.git/blob - tools/catalog-report.py
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / tools / catalog-report.py
1 #!/usr/bin/env python3
2 # -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
3 # SPDX-License-Identifier: MIT
4 #
5 # This file is distributed under the MIT license, see below.
6 #
7 # The MIT License (MIT)
8 #
9 # Permission is hereby granted, free of charge, to any person obtaining a copy
10 # of this software and associated documentation files (the "Software"), to deal
11 # in the Software without restriction, including without limitation the rights
12 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 # copies of the Software, and to permit persons to whom the Software is
14 # furnished to do so, subject to the following conditions:
15 #
16 # The above copyright notice and this permission notice shall be included in
17 # all copies or substantial portions of the Software.
18 #
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 # SOFTWARE.
26
27 """
28 Prints out journal entries with no or bad catalog explanations.
29 """
30
31 import re
32 from systemd import journal, id128
33
34 j = journal.Reader()
35
36 logged = set()
37 pattern = re.compile('@[A-Z0-9_]+@')
38
39 mids = {v:k for k,v in id128.__dict__.items()
40 if k.startswith('SD_MESSAGE')}
41
42 freq = 1000
43
44 def log_entry(x):
45 if 'CODE_FILE' in x:
46 # some of our code was using 'CODE_FUNCTION' instead of 'CODE_FUNC'
47 print('{}:{} {}'.format(x.get('CODE_FILE', '???'),
48 x.get('CODE_LINE', '???'),
49 x.get('CODE_FUNC', None) or x.get('CODE_FUNCTION', '???')))
50 print(' {}'.format(x.get('MESSAGE', 'no message!')))
51 for k, v in x.items():
52 if k.startswith('CODE_') or k in {'MESSAGE_ID', 'MESSAGE'}:
53 continue
54 print(' {}={}'.format(k, v))
55 print()
56
57 for i, x in enumerate(j):
58 if i % freq == 0:
59 print(i, end='\r')
60
61 try:
62 mid = x['MESSAGE_ID']
63 except KeyError:
64 continue
65 name = mids.get(mid, 'unknown')
66
67 try:
68 desc = journal.get_catalog(mid)
69 except FileNotFoundError:
70 if mid in logged:
71 continue
72
73 print('{} {.hex}: no catalog entry'.format(name, mid))
74 log_entry(x)
75 logged.add(mid)
76 continue
77
78 fields = [field[1:-1] for field in pattern.findall(desc)]
79 for field in fields:
80 index = (mid, field)
81 if field in x or index in logged:
82 continue
83 print('{} {.hex}: no field {}'.format(name, mid, field))
84 log_entry(x)
85 logged.add(index)