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

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