mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Recent RPM-based guests have switched from using Berkeley DB (BDB) to sqlite. In order to inspect these guests (and earlier ones) we need to stop using the hokey parsing of the BDB and use librpm APIs instead. This commit adds a new internal API so we can call librpm from the daemon, and changes the library part to use the new API for RPM-based guests. This change removes the requirement for BDB tools like db_dump. See also: http://lists.rpm.org/pipermail/rpm-ecosystem/2021-March/000751.html http://lists.rpm.org/pipermail/rpm-ecosystem/2021-March/000754.html https://blog.fpmurphy.com/2011/08/programmatically-retrieve-rpm-package-details.html This breaks the virt-inspector test (now in the separate guestfs-tools repository). However this is not a bug in libguestfs, but a bug in the phoney Fedora guest that we use for testing - we created a BDB-style RPM database which was supposed to be just enough to make the old code work. The new code using real librpm needs /usr/lib/rpm/rpmrc (not present in the phoney image) and also cannot parse the phoney database, so we will need to separately rework that test. Thanks: Panu Matilainen Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1766487 Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1409024
59 lines
2.1 KiB
OCaml
59 lines
2.1 KiB
OCaml
(* guestfs-inspection
|
|
* Copyright (C) 2009-2021 Red Hat Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*)
|
|
|
|
open Printf
|
|
|
|
open Std_utils
|
|
|
|
external rpm_init : unit -> unit = "guestfs_int_daemon_rpm_init"
|
|
external rpm_start_iterator : unit -> unit = "guestfs_int_daemon_rpm_start_iterator"
|
|
external rpm_next_application : unit -> Structs.application2 = "guestfs_int_daemon_rpm_next_application"
|
|
external rpm_end_iterator : unit -> unit = "guestfs_int_daemon_rpm_end_iterator"
|
|
|
|
(* librpm is troublesome when run from the main process. In
|
|
* particular it holds open some glibc NSS files. Therefore we fork
|
|
* before doing the chroot and any librpm operations.
|
|
*
|
|
* We could also consider in future limiting the time taken to run the
|
|
* subprocess since it's unclear that parsing RPM config files from
|
|
* the guest in particular is safe.
|
|
*)
|
|
let rec internal_list_rpm_applications () =
|
|
let chroot = Chroot.create ~name:"librpm" () in
|
|
let apps = Chroot.f chroot list_rpm_applications () in
|
|
eprintf "librpm returned %d installed packages\n%!" (List.length apps);
|
|
apps
|
|
|
|
and list_rpm_applications () =
|
|
rpm_init ();
|
|
rpm_start_iterator ();
|
|
let ret = ref [] in
|
|
let rec loop () =
|
|
try
|
|
let app = rpm_next_application () in
|
|
List.push_front app ret;
|
|
loop ()
|
|
with Not_found -> ()
|
|
in
|
|
loop ();
|
|
rpm_end_iterator ();
|
|
List.sort
|
|
(fun { Structs.app2_name = n1 } { Structs.app2_name = n2 } ->
|
|
compare n1 n2)
|
|
!ret
|