SHA256
1
0
forked from pool/supermin
supermin/0003-add-run_shell-helper.patch

51 lines
1.7 KiB
Diff

From 1ecd918f88065b55bcb411b54311d813ce54c2ad Mon Sep 17 00:00:00 2001
From: Olaf Hering <olaf@aepfle.de>
Date: Tue, 9 Apr 2013 19:27:01 +0200
Subject: add run_shell helper
The new run_shell helper is a copy of run_python,
and will be used by upcoming changes.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
src/supermin_utils.ml | 9 +++++++++
src/supermin_utils.mli | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/src/supermin_utils.ml b/src/supermin_utils.ml
index f98e09a..cb8a27e 100644
--- a/src/supermin_utils.ml
+++ b/src/supermin_utils.ml
@@ -70,6 +70,15 @@ let run_command cmd =
exit 1
)
+let run_shell code args =
+ let cmd = sprintf "sh -c %s arg0 %s"
+ (Filename.quote code)
+ (String.concat " " (List.map Filename.quote args)) in
+ if Sys.command cmd <> 0 then (
+ eprintf "supermin: external shell program failed, see earlier error messages\n";
+ exit 1
+ )
+
let run_python code args =
let cmd = sprintf "python -c %s %s"
(Filename.quote code)
diff --git a/src/supermin_utils.mli b/src/supermin_utils.mli
index 54df1e8..c4a52c6 100644
--- a/src/supermin_utils.mli
+++ b/src/supermin_utils.mli
@@ -41,6 +41,11 @@ val run_command : string -> unit
when constructing the command to properly quote any arguments
(using {!Filename.quote}). *)
+val run_shell : string -> string list -> unit
+ (** [run_shell code args] runs shell [code] with arguments [args].
+ This does not return anything, but exits with an error message
+ if the shell code returns an error. *)
+
val run_python : string -> string list -> unit
(** [run_python code args] runs Python [code] with arguments [args].
This does not return anything, but exits with an error message