Logging.xb_op ~tid:0 ~ty:Xenbus.Xb.Op.Debug ~con:"=======>" msg;
None
| "quota" :: domid :: _ ->
- let domid = int_of_string domid in
+ let domid = Utils.int_of_string_exn domid in
let quota = (Store.get_quota t.Transaction.store) in
Some (Quota.to_string quota domid ^ "\000")
| "watches" :: _ ->
History.trim ();
Some "trimmed"
| "txn" :: domid :: _ ->
- let domid = int_of_string domid in
+ let domid = Utils.int_of_string_exn domid in
let con = Connections.find_domain cons domid in
let b = Buffer.create 128 in
let () = con.transactions |> Hashtbl.iter @@ fun id tx ->
in
Some (Buffer.contents b)
| "xenbus" :: domid :: _ ->
- let domid = int_of_string domid in
+ let domid = Utils.int_of_string_exn domid in
let con = Connections.find_domain cons domid in
let s = Printf.sprintf "xenbus: %s; overflow queue length: %d, can_input: %b, has_more_input: %b, has_old_output: %b, has_new_output: %b, has_more_work: %b. pending: %s"
(Xenbus.Xb.debug con.xb)
in
Some s
| "mfn" :: domid :: _ ->
- let domid = int_of_string domid in
+ let domid = Utils.int_of_string_exn domid in
let con = Connections.find_domain cons domid in
may (fun dom -> Printf.sprintf "%nd\000" (Domain.get_mfn dom)) (Connection.get_domain con)
| _ -> None
then raise Define.Permission_denied;
let domid =
match (split None '\000' data) with
- | domid :: _ -> int_of_string domid
+ | domid :: _ -> Utils.int_of_string_exn domid
| _ -> raise Invalid_Cmd_Args
in
if domid = Define.domid_self || Domains.exist domains domid then "T\000" else "F\000"
| Quota.Limit_reached -> reply_error "EQUOTA"
| Quota.Data_too_big -> reply_error "E2BIG"
| Quota.Transaction_opened -> reply_error "EQUOTA"
- | (Failure "int_of_string") -> reply_error "EINVAL"
+ | Utils.ConversionFailed s -> reply_error "EINVAL"
| Define.Unknown_operation -> reply_error "ENOSYS"
let write_access_log ~ty ~tid ~con ~data =
let (domid, mfn, remote_port) =
match (split None '\000' data) with
| domid :: mfn :: remote_port :: _ ->
- int_of_string domid, Nativeint.of_string mfn, int_of_string remote_port
+ Utils.int_of_string_exn domid, Nativeint.of_string mfn, Utils.int_of_string_exn remote_port
| _ -> raise Invalid_Cmd_Args;
in
let dom =
then raise Define.Permission_denied;
let domid =
match (split None '\000' data) with
- | [domid;""] -> int_of_string domid
+ | [domid;""] -> Utils.int_of_string_exn domid
| _ -> raise Invalid_Cmd_Args
in
let fire_spec_watches = Domains.exist domains domid in
then raise Define.Permission_denied;
let domid =
match (split None '\000' data) with
- | domid :: _ -> int_of_string domid
+ | domid :: _ -> Utils.int_of_string_exn domid
| _ -> raise Invalid_Cmd_Args
in
if Domains.exist domains domid
) s;
Bytes.unsafe_to_string hs
+exception ConversionFailed of string
+let int_of_string_exn s =
+ match int_of_string_opt s with
+ | Some x -> x
+ | None -> raise (ConversionFailed s)
+
let unhexify hs =
- let char_of_hexseq seq0 seq1 = Char.chr (int_of_string (sprintf "0x%c%c" seq0 seq1)) in
+ let char_of_hexseq seq0 seq1 = Char.chr (int_of_string_exn (sprintf "0x%c%c" seq0 seq1)) in
let b = Bytes.create (String.length hs / 2) in
for i = 0 to Bytes.length b - 1
do
let buf = Bytes.make 20 '\000' in
let sz = Unix.read fd buf 0 20 in
Unix.close fd;
- int_of_string (Bytes.sub_string buf 0 sz)
+ int_of_string_exn (Bytes.sub_string buf 0 sz)
(* @path may be guest data and needs its length validating. @connection_path
* is generated locally in xenstored and always of the form "/local/domain/$N/" *)
e.g. a RO socket from a previous version: ignore it *)
global_f ~rw
| "evtchn-dev" :: fd :: domexc_port :: [] ->
- evtchn_f ~fd:(int_of_string fd)
- ~domexc_port:(int_of_string domexc_port)
+ evtchn_f ~fd:(Utils.int_of_string_exn fd)
+ ~domexc_port:(Utils.int_of_string_exn domexc_port)
| "socket" :: fd :: [] ->
- socket_f ~fd:(int_of_string fd)
+ socket_f ~fd:(Utils.int_of_string_exn fd)
| "dom" :: domid :: mfn :: remote_port :: rest ->
let local_port = match rest with
| [] -> None (* backward compat: old version didn't have it *)
- | local_port :: _ -> Some (int_of_string local_port) in
+ | local_port :: _ -> Some (Utils.int_of_string_exn local_port) in
domain_f ?local_port
- ~remote_port:(int_of_string remote_port)
- (int_of_string domid)
+ ~remote_port:(Utils.int_of_string_exn remote_port)
+ (Utils.int_of_string_exn domid)
(Nativeint.of_string mfn)
| "watch" :: domid :: path :: token :: [] ->
- watch_f (int_of_string domid)
+ watch_f (Utils.int_of_string_exn domid)
(unhexify path) (unhexify token)
| "store" :: path :: perms :: value :: [] ->
store_f (getpath path)
in
let global_f ~rw =
let get_listen_sock sockfd =
- let fd = sockfd |> int_of_string |> Utils.FD.of_int in
+ let fd = sockfd |> Utils.int_of_string_exn |> Utils.FD.of_int in
Unix.listen fd 1;
Some fd
in