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

51 lines
1.7 KiB
Diff

From e83608bd0b8ef62fcd950b2b848effa1e1b81d66 Mon Sep 17 00:00:00 2001
From: Olaf Hering <olaf@aepfle.de>
Date: Tue, 9 Apr 2013 18:43:11 +0200
Subject: [PATCH 1/2] 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