Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #126 from vbmithr/CA-85761

Use unbuffered I/O to read from /dev/(u)random
  • Loading branch information...
commit 2b61fac52683c47d70b3a5013853bc1557261dbb 2 parents 7a0e40e + 3e56de9
@jonludlam jonludlam authored
View
2  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)
View
4 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 $@ $<
View
22 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"
Please sign in to comment.
Something went wrong with that request. Please try again.