Skip to content

Commit b2f03c4

Browse files
author
jeromemaloberti
committed
Merge pull request xapi-project#990 from jeromemaloberti/CA-97883-tampa-lcm
CA-97883: Wrap the fstat call in an exception handler
2 parents f1a8502 + efc7a9c commit b2f03c4

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ocaml/xenguest/xenguest_main.ml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,22 @@ let tcp_keepintvl = 2
282282

283283
(* CA-94829: Set the TCP keepalive options if it's a socket *)
284284
let fix_fd fd =
285-
let stats = Unix.fstat fd in
286-
if stats.Unix.st_kind = Unix.S_SOCK then begin
287-
Unix.setsockopt fd Unix.SO_KEEPALIVE true;
288-
Unixext.set_sock_keepalives fd tcp_keepcnt tcp_keepidle tcp_keepintvl;
289-
debug "Set socket TCP keepalive values to TCP_KEEPCNT=%d TCP_KEEPIDLE=%d TCP_KEEPINTVL=%d" tcp_keepcnt tcp_keepidle tcp_keepintvl
290-
end else begin
291-
debug "Skipping TCP keepalive setting as fd is not a socket"
292-
end
293-
285+
try
286+
let stats = Unix.fstat fd in
287+
if stats.Unix.st_kind = Unix.S_SOCK then begin
288+
Unix.setsockopt fd Unix.SO_KEEPALIVE true;
289+
Unixext.set_sock_keepalives fd tcp_keepcnt tcp_keepidle tcp_keepintvl;
290+
debug "Set socket TCP keepalive values to TCP_KEEPCNT=%d TCP_KEEPIDLE=%d TCP_KEEPINTVL=%d" tcp_keepcnt tcp_keepidle tcp_keepintvl
291+
end else begin
292+
debug "Skipping TCP keepalive setting as fd is not a socket"
293+
end
294+
with
295+
| Unix.Unix_error (Unix.EOVERFLOW, _, _) ->
296+
(* Ignoring EOVERFLOW: can't get this on a socket *)
297+
debug "Skipping TCP keepalive setting as fd is not a socket";
298+
()
299+
| e ->
300+
debug "Caught exception: '%s' - ignoring" (Printexc.to_string e)
294301

295302
(* main *)
296303
let _ =

0 commit comments

Comments
 (0)