[Libguestfs] [common PATCH 2/3] mlcustomize: refactor reading from /etc/selinux/config

Pino Toscano
2020-09-23T15:57:49Z

Move the reading of values from /etc/selinux/config to an own function,
so it can be easily reused.

This is a simple refactoring.
---
 mlcustomize/SELinux_relabel.ml | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/mlcustomize/SELinux_relabel.ml b/mlcustomize/SELinux_relabel.ml
index 5df1f08..647aeda 100644
--- a/mlcustomize/SELinux_relabel.ml
+++ b/mlcustomize/SELinux_relabel.ml
@@ -62,14 +62,7 @@ and use_setfiles g    (* Get the SELinux policy name, eg.
"targeted", "minimum".
    * Use "targeted" if not specified, just like libselinux does.
    *)
-  let policy -    let config_path = "/files/etc/selinux/config" in
-    let selinuxtype_path = config_path ^ "/SELINUXTYPE" in
-    let keys = g#aug_ls config_path in
-    if array_find selinuxtype_path keys then
-      g#aug_get selinuxtype_path
-    else
-      "targeted" in
+  let policy = read_selinux_config_key g "SELINUXTYPE"
"targeted" in

   g#aug_close ();

@@ -99,3 +92,12 @@ and use_setfiles g
   (* Relabel everything. *)
   g#selinux_relabel ~force:true specfile "/"
+
+and read_selinux_config_key g key defval +  let config_path =
"/files/etc/selinux/config" in
+  let key_path = config_path ^ "/" ^ key in
+  let keys = g#aug_ls config_path in
+  if array_find key_path keys then
+    g#aug_get key_path
+  else
+    defval
--
2.26.2