This is not quite a neutral refactoring, because it means we now run
the getenforce command every time virt-v2v starts up. However it's a
trivial command that reads a single /sys file and it can't fail even
if the command is missing or on platforms that know nothing about
SELinux.
---
v2v/input_libvirt_vddk.ml | 4 ----
v2v/output_rhv_upload.ml | 4 ----
v2v/utils.ml | 4 ++++
v2v/utils.mli | 3 +++
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml
index 97c7cb532..e2efef842 100644
--- a/v2v/input_libvirt_vddk.ml
+++ b/v2v/input_libvirt_vddk.ml
@@ -108,10 +108,6 @@ class input_libvirt_vddk input_conn input_password vddk_options
parsed_uri
(* Compute the LD_LIBRARY_PATH that we may have to pass to nbdkit. *)
let library_path = Option.map (fun libdir -> libdir // libNN) libdir in
- (* Is SELinux enabled and enforcing on the host? *)
- let have_selinux =
- 0 = Sys.command "getenforce 2>/dev/null | grep -isq Enforcing" in
-
(* Check that the VDDK path looks reasonable. *)
let error_unless_vddk_libdir () =
(match libdir with
diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml
index 77c39107e..0709c8152 100644
--- a/v2v/output_rhv_upload.ml
+++ b/v2v/output_rhv_upload.ml
@@ -105,10 +105,6 @@ class output_rhv_upload output_alloc output_conn
Python_script.create ~name:"rhv-upload-createvm.py"
Output_rhv_upload_createvm_source.code in
- (* Is SELinux enabled and enforcing on the host? *)
- let have_selinux =
- 0 = Sys.command "getenforce 2>/dev/null | grep -isq Enforcing" in
-
(* Check that the 'ovirtsdk4' Python module is available. *)
let error_unless_ovirtsdk4_module_available () =
let res = run_command [ Python_script.python; "-c"; "import
ovirtsdk4" ] in
diff --git a/v2v/utils.ml b/v2v/utils.ml
index 74b501f81..9be4d2dc4 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -24,6 +24,10 @@ open Std_utils
open Tools_utils
open Common_gettext.Gettext
+(* Is SELinux enabled and enforcing on the host? *)
+let have_selinux =
+ 0 = Sys.command "getenforce 2>/dev/null | grep -isq Enforcing"
+
(* URI quoting. *)
let uri_quote str =
let len = String.length str in
diff --git a/v2v/utils.mli b/v2v/utils.mli
index 4635d4808..61cba1bbd 100644
--- a/v2v/utils.mli
+++ b/v2v/utils.mli
@@ -18,6 +18,9 @@
(** Utilities used in virt-v2v only. *)
+val have_selinux : bool
+(** True if SELinux is enabled and enforcing on the host. *)
+
val uri_quote : string -> string
(** Take a string and perform %xx escaping as used in some parts of URLs. *)
--
2.20.1