From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rob Hoes Subject: [PATCH v2 19/30] libxl: ocaml: add xen_console_read Date: Thu, 13 Jun 2013 16:25:01 +0100 Message-ID: <1371137112-16692-20-git-send-email-rob.hoes@citrix.com> References: <1371137112-16692-1-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1371137112-16692-1-git-send-email-rob.hoes@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Rob Hoes List-Id: xen-devel@lists.xenproject.org Signed-off-by: Rob Hoes --- tools/ocaml/libs/xl/xenlight.ml.in | 1 + tools/ocaml/libs/xl/xenlight.mli.in | 1 + tools/ocaml/libs/xl/xenlight_stubs.c | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/tools/ocaml/libs/xl/xenlight.ml.in b/tools/ocaml/libs/xl/xenlight.ml.in index 883df0c..fd5c4ce 100644 --- a/tools/ocaml/libs/xl/xenlight.ml.in +++ b/tools/ocaml/libs/xl/xenlight.ml.in @@ -61,5 +61,6 @@ external test_raise_exception: unit -> unit = "stub_raise_exception" external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger" external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq" external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys" +external xen_console_read : ctx -> string list = "stub_xl_xen_console_read" let _ = Callback.register_exception "Xenlight.Error" (Error(Fail, "")) diff --git a/tools/ocaml/libs/xl/xenlight.mli.in b/tools/ocaml/libs/xl/xenlight.mli.in index 34b1ce5..11ea43c 100644 --- a/tools/ocaml/libs/xl/xenlight.mli.in +++ b/tools/ocaml/libs/xl/xenlight.mli.in @@ -46,3 +46,4 @@ external test_raise_exception: unit -> unit = "stub_raise_exception" external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger" external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq" external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys" +external xen_console_read : ctx -> string list = "stub_xl_xen_console_read" diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c index e801643..cacaaca 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -557,6 +557,33 @@ value stub_xl_send_debug_keys(value ctx, value keys) CAMLreturn(Val_unit); } +value stub_xl_xen_console_read(value ctx) +{ + CAMLparam1(ctx); + CAMLlocal3(list, cons, ml_line); + int i = 0, ret; + char *console[32768], *line; + libxl_xen_console_reader *cr; + + cr = libxl_xen_console_read_start(CTX, 0); + if (cr) + for (i = 0; libxl_xen_console_read_line(CTX, cr, &line) > 0; i++) + console[i] = strdup(line); + libxl_xen_console_read_finish(CTX, cr); + + list = Val_emptylist; + for (; i > 0; i--) { + ml_line = caml_copy_string(console[i - 1]); + free(console[i - 1]); + cons = caml_alloc(2, 0); + Store_field(cons, 0, ml_line); // head + Store_field(cons, 1, list); // tail + list = cons; + } + + CAMLreturn(list); +} + /* * Local variables: * indent-tabs-mode: t -- 1.7.10.4