Skip to content

Commit 0cc3054

Browse files
committed
CA-211448: When reading a line from sysfs, translate End_of_file to "" (#79)
CA-211448: When reading a line from sysfs, translate End_of_file to "" Some sysfs files are "empty", for a good reason. Signed-off-by: Rob Hoes <[email protected]>
1 parent 99a057e commit 0cc3054

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/network_utils.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ module Sysfs = struct
7777
Printf.sprintf "/sys/class/net/%s/%s" dev attr
7878

7979
let read_one_line file =
80-
let inchan = open_in file in
8180
try
82-
let result = input_line inchan in
83-
close_in inchan;
84-
result
85-
with exn -> close_in inchan; raise (Read_error file)
81+
let inchan = open_in file in
82+
finally
83+
(fun () -> input_line inchan)
84+
(fun () -> close_in inchan)
85+
with
86+
| End_of_file -> ""
87+
| exn -> error "%s" (Printexc.to_string exn); raise (Read_error file)
8688

8789
let write_one_line file l =
8890
let outchan = open_out file in

0 commit comments

Comments
 (0)