File: ntplogtemp-handle-oserror.patch

package info (click to toggle)
ntpsec 1.2.3%2Bdfsg1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,960 kB
  • sloc: ansic: 62,004; python: 32,017; sh: 1,553; yacc: 1,293; makefile: 190; javascript: 138
file content (38 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
From 697298bd33b9138136e81ac94edaf1dec125264f Mon Sep 17 00:00:00 2001
From: Daniel <daniel@developerdan.com>
Date: Thu, 27 Feb 2025 17:37:31 -0500
Subject: [PATCH] Handle OSError when 'temp' file is not readable

Sometimes reading 'temp' generates an error message 'No data available'.
Wrapping it in a try/catch allow other temp zone to work as expected.
This bug was reported at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1098368
---
 ntpclients/ntplogtemp.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

--- a/ntpclients/ntplogtemp.py
+++ b/ntpclients/ntplogtemp.py
@@ -207,13 +207,16 @@
         _zone = 0
         _data = []
         for zone in self.zones:
-            _zone_data = open(os.path.join(zone, 'temp'))
-            for line in _zone_data:
-                temp = float(line) / 1000
-                _now = int(time.time())
-                _data.append('%d ZONE%s %s' % (_now, _zone, temp))
-                _zone += 1
-            _zone_data.close()
+            try:
+                with open(os.path.join(zone, 'temp')) as _zone_data:
+                    for line in _zone_data:
+                        temp = float(line) / 1000
+                        _now = int(time.time())
+                        _data.append('%d ZONE%s %s' % (_now, _zone, temp))
+                        _zone += 1
+            except OSError:
+                # temp might not be readable, if so continue on to the next one
+                continue
         return _data