From: David Scott Date: Tue, 16 Mar 2010 20:54:36 +0000 (+0000) Subject: CA-38120: if we fork/exec a process and it doesn't exit with 0 (ie non-zero exit... X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=af5c7572bc19e1fa22f3ff164151862d61defb27;p=xcp%2Fxen-api-libs.git CA-38120: if we fork/exec a process and it doesn't exit with 0 (ie non-zero exit or signal of some kind) then log a message to syslog containing the pid, truncated cmdline and exit status. Signed-off-by: David Scott --- diff --git a/forking_executioner/child.ml b/forking_executioner/child.ml index 7413b74..c9006f2 100644 --- a/forking_executioner/child.ml +++ b/forking_executioner/child.ml @@ -143,10 +143,25 @@ let run state comms_sock fd_sock fd_sock_path = List.iter (fun fd -> Unix.close fd) fds; let (pid,status) = Unix.waitpid [] result in + + let log_failure reason code = + (* The commandline might be too long to clip it *) + let cmdline = String.concat " " args in + let limit = 80 - 3 in + let cmdline' = if String.length cmdline > limit then String.sub cmdline 0 limit ^ "..." else cmdline in + Syslog.log Syslog.Syslog Syslog.Err (Printf.sprintf "%d (%s) %s %d" result cmdline' reason code) in + let pr = match status with - | Unix.WEXITED n -> Fe.WEXITED n - | Unix.WSIGNALED n -> Fe.WSIGNALED n - | Unix.WSTOPPED n -> Fe.WSTOPPED n + | Unix.WEXITED 0 -> Fe.WEXITED 0 + | Unix.WEXITED n -> + log_failure "exitted with code" n; + Fe.WEXITED n + | Unix.WSIGNALED n -> + log_failure "exitted with signal" n; + Fe.WSIGNALED n + | Unix.WSTOPPED n -> + log_failure "stopped with signal" n; + Fe.WSTOPPED n in let result = Fe.Finished (pr) in Fecomms.write_raw_rpc comms_sock result;