2
* Copyright (C) 2006-2009 Citrix Systems Inc.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation; version 2.1 only. with the special
7
* exception on linking described in file LICENSE.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
14
(* api to connect/start mini monitor *)
20
type answer = Ok | Error of string | Msg of string | Unknown of string
22
let string_of_answer answer =
25
| Error s -> "CMD_ERROR " ^ s
26
| Msg s -> "CMD_MSG " ^ s
29
let answer_of_string s =
32
else if String.startswith "CMD_ERROR " s then
33
Error (String.sub s 10 (String.length s - 10))
34
else if String.startswith "CMD_MSG " s then
35
Msg (String.sub s 8 (String.length s - 8))
40
let len = String.length buf in
44
let wr = Unix.write fd buf (len - !left) (!left) in
49
let b = Buffer.create 1024 in
50
let buf = String.create 1024 in
51
let quit = ref false in
54
let rd = Unix.read fd buf 0 1024 in
58
Buffer.add_substring b buf 0 rd
62
(** request s from a running xenvm identified by id (uuid or name) *)
64
let filename = Printf.sprintf "/var/lib/xenvm/vm-%s" id in
65
let fd = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
66
Unix.connect fd (Unix.ADDR_UNIX filename);
69
let answer = doread fd in
72
answer_of_string answer