summaryrefslogtreecommitdiffstats
path: root/ocaml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml')
-rw-r--r--ocaml/guestfs.ml2
-rw-r--r--ocaml/guestfs.mli6
-rw-r--r--ocaml/guestfs_c_actions.c52
3 files changed, 60 insertions, 0 deletions
diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml
index 53307944..fa2e3418 100644
--- a/ocaml/guestfs.ml
+++ b/ocaml/guestfs.ml
@@ -146,3 +146,5 @@ external mounts : t -> string array = "ocaml_guestfs_mounts"
external umount_all : t -> unit = "ocaml_guestfs_umount_all"
external lvm_remove_all : t -> unit = "ocaml_guestfs_lvm_remove_all"
external file : t -> string -> string = "ocaml_guestfs_file"
+external command : t -> string array -> string = "ocaml_guestfs_command"
+external command_lines : t -> string array -> string array = "ocaml_guestfs_command_lines"
diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli
index e3cee18f..279ed4d3 100644
--- a/ocaml/guestfs.mli
+++ b/ocaml/guestfs.mli
@@ -277,3 +277,9 @@ val lvm_remove_all : t -> unit
val file : t -> string -> string
(** determine file type *)
+val command : t -> string array -> string
+(** run a command from the guest filesystem *)
+
+val command_lines : t -> string array -> string array
+(** run a command, returning lines *)
+
diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c
index decb8383..356965dc 100644
--- a/ocaml/guestfs_c_actions.c
+++ b/ocaml/guestfs_c_actions.c
@@ -1689,3 +1689,55 @@ ocaml_guestfs_file (value gv, value pathv)
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_command (value gv, value argumentsv)
+{
+ CAMLparam2 (gv, argumentsv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("command: used handle after closing it");
+
+ char **arguments = ocaml_guestfs_strings_val (argumentsv);
+ char *r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_command (g, arguments);
+ caml_leave_blocking_section ();
+ ocaml_guestfs_free_strings (arguments);
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "command");
+
+ rv = caml_copy_string (r);
+ free (r);
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_command_lines (value gv, value argumentsv)
+{
+ CAMLparam2 (gv, argumentsv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("command_lines: used handle after closing it");
+
+ char **arguments = ocaml_guestfs_strings_val (argumentsv);
+ int i;
+ char **r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_command_lines (g, arguments);
+ caml_leave_blocking_section ();
+ ocaml_guestfs_free_strings (arguments);
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "command_lines");
+
+ rv = caml_copy_string_array ((const char **) r);
+ for (i = 0; r[i] != NULL; ++i) free (r[i]);
+ free (r);
+ CAMLreturn (rv);
+}
+