From 0fb09fa0ffb7312b489ffaf114cff17651132495 Mon Sep 17 00:00:00 2001 From: Tomasz Wroblewski Date: Mon, 30 Nov 2009 18:08:15 +0000 Subject: [PATCH] Prevent xenstored death when out-of-disk space --- libs/log/log.ml | 6 ++++-- xenstored/logging.ml | 4 +++- xenstored/xenstored.ml | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/log/log.ml b/libs/log/log.ml index 23ea6d7..4f42759 100644 --- a/libs/log/log.ml +++ b/libs/log/log.ml @@ -225,7 +225,9 @@ let output t ?(key="") ?(extra="") priority (message: string) = (* log-rotate at appropriate times *) let write_to_stream stream = let string = (construct_string true) in - fprintf stream "%s\n%!" string; + try + fprintf stream "%s\n%!" string + with _ -> () (* Trap exception when we fail to write log *) in if String.length message > 0 then @@ -249,7 +251,7 @@ let log t level (fmt: ('a, unit, string, unit) format4): 'a = (* ksprintf is the preferred name for kprintf, but the former * is not available in OCaml 3.08.3 *) Printf.kprintf (if b then output t level else (fun _ -> ())) fmt - + let debug t (fmt: ('a , unit, string, unit) format4) = log t Debug fmt let info t (fmt: ('a , unit, string, unit) format4) = log t Info fmt let warn t (fmt: ('a , unit, string, unit) format4) = log t Warn fmt diff --git a/xenstored/logging.ml b/xenstored/logging.ml index 19fbfe4..639ac2a 100644 --- a/xenstored/logging.ml +++ b/xenstored/logging.ml @@ -193,7 +193,9 @@ let init aal save_to_disk = access := Some (make save_to_disk) let write_access_log ~con ~tid ?data access_type = - Pervasiveext.maybe (fun a -> a.write access_type ~con ~tid ?data) !access + try + Pervasiveext.maybe (fun a -> a.write access_type ~con ~tid ?data) !access + with _ -> () let new_connection = write_access_log Newconn let end_connection = write_access_log Endconn diff --git a/xenstored/xenstored.ml b/xenstored/xenstored.ml index 1fc43cf..9465d77 100644 --- a/xenstored/xenstored.ml +++ b/xenstored/xenstored.ml @@ -226,7 +226,9 @@ let _ = let cf = do_argv in let pidfile = parse_config (config_filename cf) in - Unixext.mkdir_rec (Filename.dirname pidfile) 0o755; + (try + Unixext.mkdir_rec (Filename.dirname pidfile) 0o755 + with _ -> ()); let rw_sock, ro_sock = if cf.disable_socket then @@ -239,7 +241,9 @@ let _ = if cf.daemonize then Unixext.daemonize (); - Unixext.pidfile_write pidfile; + (try + Unixext.pidfile_write pidfile + with _ -> ()); info "Xen Storage Daemon, version %d.%d" Define.xenstored_major Define.xenstored_minor; -- 2.39.5