[Libguestfs] [PATCH] mllib: do not assume $PATH is set

Pino Toscano ptoscano at redhat.com
Tue Aug 23 14:00:18 UTC 2016


Make 'which' gracefully handle the case where $PATH is not set
(it will raise Executable_not_found, but that is the expected thing to
do).

Related to RHBZ#1367839.
---
 mllib/common_utils.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index fdca713..9210cf8 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -319,7 +319,9 @@ let protect ~f ~finally =
   match r with Either ret -> ret | Or exn -> raise exn
 
 let which executable =
-  let paths = String.nsplit ":" (Sys.getenv "PATH") in
+  let paths =
+    try String.nsplit ":" (Sys.getenv "PATH")
+    with Not_found -> [] in
   let paths = filter_map (
     fun p ->
       let path = p // executable in
-- 
2.7.4




More information about the Libguestfs mailing list