Skip to content

Commit 0a0a0d9

Browse files
committed
deleted-libraries.py: fix exception handling and miss-counting
EnvironmentError exceptions deprecated since Python 3.3 and are now longer used. I have this changes running since over a year now and have never encountered any other exceptions than FileNotFoundError or ProcessLookupError. Also due to an indentation error the metric values could never reach anything above 1 even if the outdated library is used more than once. Signed-off-by: Christian Pointner <equinox@spreadspace.org>
1 parent 34dd42e commit 0a0a0d9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

deleted_libraries.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
been updated, perhaps due security vulnerabilities.
88
"""
99

10-
import errno
1110
import glob
1211
import os
13-
import sys
1412
from prometheus_client import CollectorRegistry, Gauge, generate_latest
1513

1614

@@ -31,15 +29,18 @@ def main():
3129
if path not in processes_linking_deleted_libraries:
3230
processes_linking_deleted_libraries[path] = {}
3331

34-
if library in processes_linking_deleted_libraries[path]:
35-
processes_linking_deleted_libraries[path][library] += 1
36-
else:
37-
processes_linking_deleted_libraries[path][library] = 1
38-
except EnvironmentError as e:
32+
if library in processes_linking_deleted_libraries[path]:
33+
processes_linking_deleted_libraries[path][library] += 1
34+
else:
35+
processes_linking_deleted_libraries[path][library] = 1
36+
except FileNotFoundError:
3937
# Ignore non-existent files, since the files may have changed since
4038
# we globbed.
41-
if e.errno != errno.ENOENT:
42-
sys.exit('Failed to open file: {0}'.format(path))
39+
pass
40+
except ProcessLookupError:
41+
# If process vanishes while collecting the linked libs reading lines from
42+
# the map file yields this error.
43+
pass
4344

4445
num_processes_per_library = {}
4546

0 commit comments

Comments
 (0)