[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH] Log when fork/exec()ed programs fail for debugging



# HG changeset patch
# User David Scott <dave.scott@xxxxxxxxxxxxx>
# Date 1268772876 0
# Node ID 194044dccbca88d5b1de83f91c2394f64205ea53
# Parent  b0519bd2911ded9c7dda1fd9b8b8962515c8b7f0
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 <dave.scott@xxxxxxxxxxxxx>

diff -r b0519bd2911d -r 194044dccbca forking_executioner/child.ml
--- a/forking_executioner/child.ml      Mon Feb 15 17:35:01 2010 +0000
+++ b/forking_executioner/child.ml      Tue Mar 16 20:54:36 2010 +0000
@@ -143,10 +143,25 @@
 
       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;
1 file changed, 18 insertions(+), 3 deletions(-)
forking_executioner/child.ml |   21 ++++++++++++++++++---


Attachment: xen-api-libs.hg.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.