Blame SOURCES/0014-customize-Support-Rocky-Linux.patch

736f6f
From 1bbc3f0f3f61f00230ed5edab0cdd72729423b58 Mon Sep 17 00:00:00 2001
736f6f
From: "Richard W.M. Jones" <rjones@redhat.com>
736f6f
Date: Mon, 10 Oct 2022 13:54:52 +0100
736f6f
Subject: [PATCH] customize: Support Rocky Linux
736f6f
736f6f
Also updates common submodule with equivalent fix for
736f6f
common/mlcustomize
736f6f
736f6f
Reported-by: Harry Benson
736f6f
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2133443
736f6f
(cherry picked from commit 8858fc63e63ae3f7c76d3ca96cbf63f43e76c834)
736f6f
---
736f6f
 common                   | 2 +-
736f6f
 customize/hostname.ml    | 3 ++-
736f6f
 customize/password.ml    | 3 ++-
736f6f
 customize/random_seed.ml | 3 ++-
736f6f
 4 files changed, 7 insertions(+), 4 deletions(-)
736f6f
736f6f
Submodule common fd964c1ba..85f3e4d08:
736f6f
diff --git a/common/mlcustomize/firstboot.ml b/common/mlcustomize/firstboot.ml
736f6f
index 5c7fd0d..0c76283 100644
736f6f
--- a/common/mlcustomize/firstboot.ml
736f6f
+++ b/common/mlcustomize/firstboot.ml
736f6f
@@ -151,7 +151,8 @@ WantedBy=%s
736f6f
 
736f6f
   and install_sysvinit_service g root distro major =
736f6f
     match distro with
736f6f
-    | "fedora"|"rhel"|"centos"|"scientificlinux"|"oraclelinux"|"redhat-based" ->
736f6f
+    | "fedora"|"rhel"|"centos"|"scientificlinux"|"oraclelinux"|"rocky"|
736f6f
+        "redhat-based" ->
736f6f
       install_sysvinit_redhat g
736f6f
     | "opensuse"|"sles"|"suse-based" ->
736f6f
       install_sysvinit_suse g
736f6f
diff --git a/common/mlpcre/pcre-c.c b/common/mlpcre/pcre-c.c
736f6f
index f780832..6d119ae 100644
736f6f
--- a/common/mlpcre/pcre-c.c
736f6f
+++ b/common/mlpcre/pcre-c.c
736f6f
@@ -278,7 +278,6 @@ guestfs_int_pcre_sub (value nv)
736f6f
   CAMLparam1 (nv);
736f6f
   const int n = Int_val (nv);
736f6f
   CAMLlocal1 (strv);
736f6f
-  CLEANUP_FREE char *str = NULL;
736f6f
   const struct last_match *m = pthread_getspecific (last_match);
736f6f
   PCRE2_SIZE len;
736f6f
   int r;
736f6f
diff --git a/common/mltools/on_exit.ml b/common/mltools/on_exit.ml
736f6f
index cae12e7..f8ef74e 100644
736f6f
--- a/common/mltools/on_exit.ml
736f6f
+++ b/common/mltools/on_exit.ml
736f6f
@@ -23,39 +23,39 @@ open Common_gettext.Gettext
736f6f
 open Unix
736f6f
 open Printf
736f6f
 
736f6f
-(* List of files to unlink. *)
736f6f
-let files = ref []
736f6f
+type action =
736f6f
+  | Unlink of string     (* filename *)
736f6f
+  | Rm_rf of string      (* directory *)
736f6f
+  | Kill of int * int    (* signal, pid *)
736f6f
+  | Fn of (unit -> unit) (* generic function *)
736f6f
 
736f6f
-(* List of directories to remove. *)
736f6f
-let rmdirs = ref []
736f6f
-
736f6f
-(* List of PIDs to kill. *)
736f6f
-let kills = ref []
736f6f
-
736f6f
-(* List of functions to call. *)
736f6f
-let fns = ref []
736f6f
+(* List of (priority, action). *)
736f6f
+let actions = ref []
736f6f
 
736f6f
 (* Perform a single exit action, printing any exception but
736f6f
  * otherwise ignoring failures.
736f6f
  *)
736f6f
-let do_action f arg =
736f6f
-  try f arg with exn -> debug "%s" (Printexc.to_string exn)
736f6f
+let do_action action =
736f6f
+  try
736f6f
+    match action with
736f6f
+    | Unlink file -> Unix.unlink file
736f6f
+    | Rm_rf dir ->
736f6f
+       let cmd = sprintf "rm -rf -- %s" (Filename.quote dir) in
736f6f
+       ignore (Tools_utils.shell_command cmd)
736f6f
+    | Kill (signal, pid) ->
736f6f
+       kill pid signal
736f6f
+    | Fn f -> f ()
736f6f
+  with exn -> debug "%s" (Printexc.to_string exn)
736f6f
 
736f6f
 (* Make sure the actions are performed only once. *)
736f6f
 let done_actions = ref false
736f6f
 
736f6f
-(* Perform the exit actions. *)
736f6f
+(* Perform the exit actions in priority order (lowest prio first). *)
736f6f
 let do_actions () =
736f6f
   if not !done_actions then (
736f6f
-    List.iter (do_action (fun f -> f ())) !fns;
736f6f
-    List.iter (do_action (fun (signal, pid) -> kill pid signal)) !kills;
736f6f
-    List.iter (do_action (fun file -> Unix.unlink file)) !files;
736f6f
-    List.iter (do_action (
736f6f
-      fun dir ->
736f6f
-        let cmd = sprintf "rm -rf -- %s" (Filename.quote dir) in
736f6f
-        ignore (Tools_utils.shell_command cmd)
736f6f
-      )
736f6f
-    ) !rmdirs;
736f6f
+    let actions = List.sort (fun (a, _) (b, _) -> compare a b) !actions in
736f6f
+    let actions = List.map snd actions in
736f6f
+    List.iter do_action actions
736f6f
   );
736f6f
   done_actions := true
736f6f
 
736f6f
@@ -94,18 +94,18 @@ let register () =
736f6f
   );
736f6f
   registered := true
736f6f
 
736f6f
-let f fn =
736f6f
+let f ?(prio = 5000) fn =
736f6f
   register ();
736f6f
-  List.push_front fn fns
736f6f
+  List.push_front (prio, Fn fn) actions
736f6f
 
736f6f
-let unlink filename =
736f6f
+let unlink ?(prio = 5000) filename =
736f6f
   register ();
736f6f
-  List.push_front filename files
736f6f
+  List.push_front (prio, Unlink filename) actions
736f6f
 
736f6f
-let rm_rf dir =
736f6f
+let rm_rf ?(prio = 5000) dir =
736f6f
   register ();
736f6f
-  List.push_front dir rmdirs
736f6f
+  List.push_front (prio, Rm_rf dir) actions
736f6f
 
736f6f
-let kill ?(signal = Sys.sigterm) pid =
736f6f
+let kill ?(prio = 5000) ?(signal = Sys.sigterm) pid =
736f6f
   register ();
736f6f
-  List.push_front (signal, pid) kills
736f6f
+  List.push_front (prio, Kill (signal, pid)) actions
736f6f
diff --git a/common/mltools/on_exit.mli b/common/mltools/on_exit.mli
736f6f
index 9bcf104..66a8554 100644
736f6f
--- a/common/mltools/on_exit.mli
736f6f
+++ b/common/mltools/on_exit.mli
736f6f
@@ -28,6 +28,12 @@
736f6f
     killing another process, so we provide simple
736f6f
     wrappers for those common actions here.
736f6f
 
736f6f
+    Actions can be ordered by setting the optional [?prio]
736f6f
+    parameter in the range 0..9999.  By default actions
736f6f
+    have priority 5000.  Lower numbered actions run first.
736f6f
+    Higher numbered actions run last.  So to have an action
736f6f
+    run at the very end before exit you might use [~prio:9999]
736f6f
+
736f6f
     Note this module registers signal handlers for
736f6f
     SIGINT, SIGQUIT, SIGTERM and SIGHUP.  This means
736f6f
     that any program that links with mltools.cmxa
736f6f
@@ -39,18 +45,20 @@
736f6f
     Your cleanup action might no longer run unless the
736f6f
     program calls {!Stdlib.exit}. *)
736f6f
 
736f6f
-val f : (unit -> unit) -> unit
736f6f
+val f : ?prio:int -> (unit -> unit) -> unit
736f6f
 (** Register a function [f] which runs when the program exits.
736f6f
     Similar to [Stdlib.at_exit] but also runs if the program is
736f6f
-    killed with a signal that we can catch. *)
736f6f
+    killed with a signal that we can catch.
736f6f
 
736f6f
-val unlink : string -> unit
736f6f
+    [?prio] is the priority, default 5000.  See the description above. *)
736f6f
+
736f6f
+val unlink : ?prio:int -> string -> unit
736f6f
 (** Unlink a single temporary file on exit. *)
736f6f
 
736f6f
-val rm_rf : string -> unit
736f6f
+val rm_rf : ?prio:int -> string -> unit
736f6f
 (** Recursively remove a temporary directory on exit (using [rm -rf]). *)
736f6f
 
736f6f
-val kill : ?signal:int -> int -> unit
736f6f
+val kill : ?prio:int -> ?signal:int -> int -> unit
736f6f
 (** Kill [PID] on exit.  The signal sent defaults to [Sys.sigterm].
736f6f
 
736f6f
     Use this with care since you can end up unintentionally killing
736f6f
diff --git a/common/options/decrypt.c b/common/options/decrypt.c
736f6f
index 97c8b88..19fe93c 100644
736f6f
--- a/common/options/decrypt.c
736f6f
+++ b/common/options/decrypt.c
736f6f
@@ -38,6 +38,10 @@
736f6f
 
736f6f
 #include "options.h"
736f6f
 
736f6f
+#ifndef __clang__
736f6f
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
736f6f
+#endif
736f6f
+
736f6f
 static void
736f6f
 append_char (size_t *idx, char *buffer, char c)
736f6f
 {
736f6f
@@ -55,6 +59,8 @@ append_char (size_t *idx, char *buffer, char c)
736f6f
   ++*idx;
736f6f
 }
736f6f
 
736f6f
+
736f6f
+
736f6f
 /**
736f6f
  * Make a LUKS map name from the partition or logical volume name, eg.
736f6f
  * C<"/dev/vda2" =E<gt> "cryptvda2">, or C<"/dev/vg-ssd/lv-root7" =E<gt>
736f6f
@@ -196,8 +202,8 @@ decrypt_mountables (guestfs_h *g, const char * const *mountables,
736f6f
 void
736f6f
 inspect_do_decrypt (guestfs_h *g, struct key_store *ks)
736f6f
 {
736f6f
+  const char *lvm2_feature[] = { "lvm2", NULL };
736f6f
   CLEANUP_FREE_STRING_LIST char **partitions = guestfs_list_partitions (g);
736f6f
-  CLEANUP_FREE_STRING_LIST char **lvs = NULL;
736f6f
   bool need_rescan;
736f6f
 
736f6f
   if (partitions == NULL)
736f6f
@@ -205,13 +211,17 @@ inspect_do_decrypt (guestfs_h *g, struct key_store *ks)
736f6f
 
736f6f
   need_rescan = decrypt_mountables (g, (const char * const *)partitions, ks);
736f6f
 
736f6f
-  if (need_rescan) {
736f6f
-    if (guestfs_lvm_scan (g, 1) == -1)
736f6f
+  if (guestfs_feature_available (g, (char **) lvm2_feature) > 0) {
736f6f
+    CLEANUP_FREE_STRING_LIST char **lvs = NULL;
736f6f
+
736f6f
+    if (need_rescan) {
736f6f
+      if (guestfs_lvm_scan (g, 1) == -1)
736f6f
+        exit (EXIT_FAILURE);
736f6f
+    }
736f6f
+
736f6f
+    lvs = guestfs_lvs (g);
736f6f
+    if (lvs == NULL)
736f6f
       exit (EXIT_FAILURE);
736f6f
+    decrypt_mountables (g, (const char * const *)lvs, ks);
736f6f
   }
736f6f
-
736f6f
-  lvs = guestfs_lvs (g);
736f6f
-  if (lvs == NULL)
736f6f
-    exit (EXIT_FAILURE);
736f6f
-  decrypt_mountables (g, (const char * const *)lvs, ks);
736f6f
 }
736f6f
diff --git a/common/utils/guestfs-utils.h b/common/utils/guestfs-utils.h
736f6f
index d568ed3..fdd85ca 100644
736f6f
--- a/common/utils/guestfs-utils.h
736f6f
+++ b/common/utils/guestfs-utils.h
736f6f
@@ -32,6 +32,7 @@
736f6f
 #ifndef GUESTFS_UTILS_H_
736f6f
 #define GUESTFS_UTILS_H_
736f6f
 
736f6f
+#include <stdio.h>
736f6f
 #include <stdbool.h>
736f6f
 
736f6f
 #include "guestfs-internal-all.h"
736f6f
diff --git a/common/utils/utils.c b/common/utils/utils.c
736f6f
index 70e55cb..0144dc4 100644
736f6f
--- a/common/utils/utils.c
736f6f
+++ b/common/utils/utils.c
736f6f
@@ -654,7 +654,8 @@ guestfs_int_hexdump (const void *data, size_t len, FILE *fp)
736f6f
 const char *
736f6f
 guestfs_int_strerror (int errnum, char *buf, size_t buflen)
736f6f
 {
736f6f
-#ifdef _GNU_SOURCE
736f6f
+#ifdef HAVE_DECL_STRERROR_R
736f6f
+#ifdef STRERROR_R_CHAR_P
736f6f
   /* GNU strerror_r */
736f6f
   return strerror_r (errnum, buf, buflen);
736f6f
 #else
736f6f
@@ -664,4 +665,7 @@ guestfs_int_strerror (int errnum, char *buf, size_t buflen)
736f6f
     snprintf (buf, buflen, "error number %d", errnum);
736f6f
   return buf;
736f6f
 #endif
736f6f
+#else /* !HAVE_DECL_STRERROR_R */
736f6f
+  return strerror (errnum);	/* YOLO it. */
736f6f
+#endif
736f6f
 }
736f6f
diff --git a/common/windows/windows.c b/common/windows/windows.c
736f6f
index b441097..355d79a 100644
736f6f
--- a/common/windows/windows.c
736f6f
+++ b/common/windows/windows.c
736f6f
@@ -58,8 +58,6 @@ is_windows (guestfs_h *g, const char *root)
736f6f
   return w;
736f6f
 }
736f6f
 
736f6f
-#pragma GCC diagnostic push
736f6f
-#pragma GCC diagnostic ignored "-Wanalyzer-null-argument"
736f6f
 /**
736f6f
  * Resolves C<path> as possible Windows path according to C<root>,
736f6f
  * giving a new path that can be used in libguestfs API calls.
736f6f
@@ -125,7 +123,6 @@ windows_path (guestfs_h *g, const char *root, const char *path, int readonly)
736f6f
 
736f6f
   return ret;
736f6f
 }
736f6f
-#pragma GCC diagnostic pop
736f6f
 
736f6f
 static void
736f6f
 mount_drive_letter (guestfs_h *g, char drive_letter, const char *root,
736f6f
diff --git a/customize/hostname.ml b/customize/hostname.ml
736f6f
index df64a2dab..fabba3cfd 100644
736f6f
--- a/customize/hostname.ml
736f6f
+++ b/customize/hostname.ml
736f6f
@@ -36,7 +36,8 @@ let rec set_hostname (g : Guestfs.guestfs) root hostname =
736f6f
     update_etc_machine_info g hostname;
736f6f
     true
736f6f
 
736f6f
-  | "linux", ("rhel"|"centos"|"scientificlinux"|"oraclelinux"|"redhat-based"), v
736f6f
+  | "linux", ("rhel"|"centos"|"scientificlinux"|"oraclelinux"|"rocky"|
736f6f
+              "redhat-based"), v
736f6f
     when v >= 7 ->
736f6f
     update_etc_hostname g hostname;
736f6f
     update_etc_machine_info g hostname;
736f6f
diff --git a/customize/password.ml b/customize/password.ml
736f6f
index 608bf95dc..b37b31fcd 100644
736f6f
--- a/customize/password.ml
736f6f
+++ b/customize/password.ml
736f6f
@@ -160,7 +160,8 @@ and default_crypto g root =
736f6f
   let distro = g#inspect_get_distro root in
736f6f
   let major = g#inspect_get_major_version root in
736f6f
   match distro, major with
736f6f
-  | ("rhel"|"centos"|"scientificlinux"|"oraclelinux"|"redhat-based"), v when v >= 9 ->
736f6f
+  | ("rhel"|"centos"|"scientificlinux"|"oraclelinux"|"rocky"|
736f6f
+     "redhat-based"), v when v >= 9 ->
736f6f
     `YESCRYPT
736f6f
   | ("rhel"|"centos"|"scientificlinux"|"oraclelinux"|"redhat-based"), v when v >= 6 ->
736f6f
     `SHA512
736f6f
diff --git a/customize/random_seed.ml b/customize/random_seed.ml
736f6f
index f32d3194e..2dcb700ea 100644
736f6f
--- a/customize/random_seed.ml
736f6f
+++ b/customize/random_seed.ml
736f6f
@@ -47,7 +47,8 @@ let rec set_random_seed (g : Guestfs.guestfs) root =
736f6f
     let distro = g#inspect_get_distro root in
736f6f
     let file =
736f6f
       match typ, distro with
736f6f
-      | "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"oraclelinux"|"redhat-based") ->
736f6f
+      | "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"oraclelinux"|
736f6f
+                  "rocky"|"redhat-based") ->
736f6f
         Some "/var/lib/random-seed"
736f6f
       | "linux", ("debian"|"ubuntu"|"kalilinux") ->
736f6f
         Some "/var/lib/urandom/random-seed"
736f6f
-- 
736f6f
2.31.1
736f6f