[Pkg-nagios-devel] Bug#1070073: check_libs_ng sometimes returns "No such file or directory"
Evgeni Golov
evgeni at debian.org
Tue Apr 30 06:45:41 BST 2024
On Mon, Apr 29, 2024 at 08:35:28PM +0200, Evgeni Golov wrote:
> UNKNOWN Exception: [Errno 2] No such file or directory: <some map file>
>
> This is because the process might have already ended between calling
> os.listdir() and os.stat().
Turns out, os.path.realpath() also can raise FileNotFoundError.
Updated patch attached.
-------------- next part --------------
diff --git a/check_libs_ng/check_libs_ng b/check_libs_ng/check_libs_ng
index f260491..d042326 100644
--- a/check_libs_ng/check_libs_ng
+++ b/check_libs_ng/check_libs_ng
@@ -61,15 +61,18 @@ def main():
logger.debug('checking process %s', proc_name)
os.chdir(os.path.join(proc, 'map_files'))
for map_file in os.listdir('.'):
- # all files in /map_files/ are absolute symlinks, so we don't need abspath()
- real_map_file_path = os.path.realpath(map_file)
- if not '/lib/' in real_map_file_path:
- logger.debug('skipping non-lib path %s', real_map_file_path)
- continue
- else:
- logger.debug('checking lib %s', real_map_file_path)
- if os.stat(map_file).st_nlink == 0:
- needs_reload.setdefault(proc_name, set()).add(proc_pid)
+ try:
+ # all files in /map_files/ are absolute symlinks, so we don't need abspath()
+ real_map_file_path = os.path.realpath(map_file)
+ if not '/lib/' in real_map_file_path:
+ logger.debug('skipping non-lib path %s', real_map_file_path)
+ continue
+ else:
+ logger.debug('checking lib %s', real_map_file_path)
+ if os.stat(map_file).st_nlink == 0:
+ needs_reload.setdefault(proc_name, set()).add(proc_pid)
+ except FileNotFoundError:
+ pass
else:
logger.debug('skipping kernel process %s', os.path.basename(proc))
More information about the Pkg-nagios-devel
mailing list