Permalink
Browse files

CA-86756: add Unixext.string_of_signal and use it to pretty-print sig…

…nals

Rather than use the ocaml-specific signal numbers, look up the standard
unix string (eg SIGTERM)

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
  • Loading branch information...
1 parent 9d2c780 commit 9ff053878049dc987c20f4f12aaf84b0ae0d8eab David Scott committed Jul 23, 2012
Showing with 38 additions and 35 deletions.
  1. +2 −2 forking_executioner/child.ml
  2. +0 −1 stdext/Makefile
  3. +2 −2 stdext/gzip.ml
  4. +0 −27 stdext/os.ml
  5. +0 −3 stdext/os.mli
  6. +27 −0 stdext/unixext.ml
  7. +7 −0 stdext/unixext.mli
@@ -195,10 +195,10 @@ let run state comms_sock fd_sock fd_sock_path =
if n <> 0 then log_failure "exitted with code" n;
Fe.WEXITED n
| Unix.WSIGNALED n ->
- log_failure "exitted with signal" n;
+ log_failure (Printf.sprintf "exitted with signal: %s" (Unixext.string_of_signal n));
Fe.WSIGNALED n
| Unix.WSTOPPED n ->
- log_failure "stopped with signal" n;
+ log_failure (Printf.sprintf "stopped with signal: %s" (Unixext.string_of_signal n));
Fe.WSTOPPED n
in
let result = Fe.Finished (pr) in
View
@@ -39,7 +39,6 @@ STDEXT_OBJS = \
backtrace \
tar \
mapext \
- os \
either \
lazyList \
extentlistSet \
View
@@ -86,8 +86,8 @@ let go (mode: zcat_mode) (input: input_type) fd f =
match snd (Forkhelpers.waitpid pid) with
| Unix.WEXITED 0 -> ();
| Unix.WEXITED i -> failwith_error (Printf.sprintf "exit code %d" i)
- | Unix.WSIGNALED i -> failwith_error (Printf.sprintf "killed by signal %d" i)
- | Unix.WSTOPPED i -> failwith_error (Printf.sprintf "stopped by signal %d" i)
+ | Unix.WSIGNALED i -> failwith_error (Printf.sprintf "killed by signal: %s" (Unixext.string_of_signal i))
+ | Unix.WSTOPPED i -> failwith_error (Printf.sprintf "stopped by signal: %s" (Unixext.string_of_signal i))
)
) (fun () -> List.iter close !to_close)
View
@@ -1,27 +0,0 @@
-let check_exit_status = function
- | Unix.WEXITED 0 -> true
- | Unix.WEXITED r -> Printf.eprintf "warning: the process terminated with exit code (%d)\n%!" r; false
- | Unix.WSIGNALED n -> Printf.eprintf "warning: the process was killed by a signal (number: %d)\n%!" n; false
- | Unix.WSTOPPED n -> Printf.eprintf "warning: the process was stopped by a signal (number: %d)\n%!" n; false
-;;
-
-let was_successful = function
- | Unix.WEXITED 0 -> true
- | Unix.WEXITED r -> false
- | Unix.WSIGNALED n -> false
- | Unix.WSTOPPED n -> false
-
-let syscall : ?env:string array -> string -> string * string * Unix.process_status = fun ?(env=[| |]) cmd ->
- print_endline cmd;
- let ic, oc, ec = Unix.open_process_full cmd env in
- let buf1 = Buffer.create 96
- and buf2 = Buffer.create 48 in
- (try while true do Buffer.add_channel buf1 ic 1 done
- with End_of_file -> ());
- (try while true do Buffer.add_channel buf2 ec 1 done
- with End_of_file -> ());
- let exit_status = Unix.close_process_full (ic, oc, ec) in
- check_exit_status exit_status;
- (Buffer.contents buf1,
- Buffer.contents buf2,
- exit_status)
View
@@ -1,3 +0,0 @@
-val check_exit_status : Unix.process_status -> bool
-val was_successful : Unix.process_status -> bool
-val syscall : ?env:string array -> string -> string * string * Unix.process_status
View
@@ -362,6 +362,33 @@ let kill_and_wait ?(signal = Sys.sigterm) ?(timeout=10.) pid =
raise Process_still_alive;
)
+let string_of_signal x =
+ let table = [
+ Sys.sigabrt, "SIGABRT";
+ Sys.sigalrm, "SIGALRM";
+ Sys.sigfpe, "SIGFPE";
+ Sys.sighup, "SIGHUP";
+ Sys.sigill, "SIGILL";
+ Sys.sigint, "SIGINT";
+ Sys.sigkill, "SIGKILL";
+ Sys.sigpipe, "SIGPIPE";
+ Sys.sigquit, "SIGQUIT";
+ Sys.sigsegv, "SIGSEGV";
+ Sys.sigterm, "SIGTERM";
+ Sys.sigusr1, "SIGUSR1";
+ Sys.sigusr2, "SIGUSR2";
+ Sys.sigchld, "SIGCHLD";
+ Sys.sigcont, "SIGCONT";
+ Sys.sigstop, "SIGSTOP";
+ Sys.sigttin, "SIGTTIN";
+ Sys.sigttou, "SIGTTOU";
+ Sys.sigvtalrm, "SIGVTALRM";
+ Sys.sigprof, "SIGPROF";
+ ] in
+ if List.mem_assoc x table
+ then List.assoc x table
+ else (Printf.sprintf "(ocaml signal %d with an unknown name)" x)
+
let proxy (a: Unix.file_descr) (b: Unix.file_descr) =
let size = 64 * 1024 in
(* [a'] is read from [a] and will be written to [b] *)
View
@@ -92,8 +92,15 @@ val delete_empty_file : string -> bool
exception Host_not_found of string
val open_connection_fd : string -> int -> Unix.file_descr
val open_connection_unix_fd : string -> Unix.file_descr
+
+
exception Process_still_alive
val kill_and_wait : ?signal:int -> ?timeout:float -> int -> unit
+
+(** [string_of_signal x] translates an ocaml signal number into
+ a string suitable for logging. *)
+val string_of_signal : int -> string
+
val proxy : Unix.file_descr -> Unix.file_descr -> unit
val really_read : Unix.file_descr -> string -> int -> int -> unit
val really_read_string : Unix.file_descr -> int -> string

0 comments on commit 9ff0538

Please sign in to comment.