diff --git a/close-and-exec/Makefile b/close-and-exec/Makefile index 3547129..b38a5bb 100644 --- a/close-and-exec/Makefile +++ b/close-and-exec/Makefile @@ -16,7 +16,7 @@ bins: $(PROGRAMS) libs: $(LIBS) closeandexec: closeandexec.cmxa closeandexec_main.cmx all - $(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -I ../stdext -I ../uuid uuid.cmxa unix.cmxa threads.cmxa stdext.cmxa closeandexec.cmxa closeandexec_main.cmx -o $@ + $(OCAMLOPT) $(OCAMLOPTFLAGS) -thread -I ../stdext -I ../uuid unix.cmxa threads.cmxa uuid.cmxa stdext.cmxa closeandexec.cmxa closeandexec_main.cmx -o $@ closeandexec.cmxa: $(foreach obj,$(OBJS),$(obj).cmx) $(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ $(foreach obj,$(OBJS),$(obj).cmx) diff --git a/forking_executioner/Makefile b/forking_executioner/Makefile index 7862b0a..450873b 100644 --- a/forking_executioner/Makefile +++ b/forking_executioner/Makefile @@ -17,10 +17,10 @@ bins: $(PROGRAMS) libs: $(LIBS) test_forker: test_forker.cmx - $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../uuid -I ../stdext uuid.cmxa rpc.cmx jsonrpc.cmx -I ../log unix.cmxa stdext.cmxa test_forker.cmx -o $@ + $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../uuid -I ../stdext unix.cmxa uuid.cmxa rpc.cmx jsonrpc.cmx -I ../log stdext.cmxa test_forker.cmx -o $@ fe: fe_debug.cmx child.cmx fe_main.cmx - $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../stdext -I ../uuid -I ../log log.cmxa uuid.cmxa unix.cmxa rpc.cmx jsonrpc.cmx stdext.cmxa fe_debug.cmx child.cmx fe_main.cmx -o $@ + $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../rpc-light -I ../stdext -I ../uuid -I ../log log.cmxa unix.cmxa uuid.cmxa rpc.cmx jsonrpc.cmx stdext.cmxa fe_debug.cmx child.cmx fe_main.cmx -o $@ %.cmo: %.ml $(OCAMLC) -c -I ../log -I ../uuid -I ../stdext -thread -o $@ $< diff --git a/uuid/uuid.ml b/uuid/uuid.ml index 8acab0b..96ba7d2 100644 --- a/uuid/uuid.ml +++ b/uuid/uuid.ml @@ -57,14 +57,20 @@ let rnd_array n = Array.of_list (rnd_list n []) let read_array dev n = - let ic = open_in_bin dev in - try - let result = Array.init n (fun _ -> input_byte ic) in - close_in ic; - result - with e -> - close_in ic; - raise e + let fd = Unix.openfile dev [Unix.O_RDONLY] 0o640 in + let finally body_f clean_f = + try + let ret = body_f () in clean_f (); ret + with e -> clean_f (); raise e in + finally + (fun () -> + let buf = String.create n in + let read = Unix.read fd buf 0 n in + if read <> n then raise End_of_file + else + Array.init n (fun i -> Char.code buf.[i]) + ) + (fun () -> Unix.close fd) let uuid_of_int_array uuid = Printf.sprintf "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"