Re: [Libguestfs] [PATCH 1/2] lib: Allow db_dump package to be a weak dependency (RHBZ#1409024).

Pino Toscano
Fri, 06 Oct 2017 08:09:03 -0000

On Thursday, 5 October 2017 15:41:31 CEST Richard W.M. Jones
wrote:
> ---
>  lib/inspect-apps.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/lib/inspect-apps.c b/lib/inspect-apps.c
> index f0cf16b38..020a3332c 100644
> --- a/lib/inspect-apps.c
> +++ b/lib/inspect-apps.c
> @@ -122,9 +122,14 @@ guestfs_impl_inspect_list_applications2 (guestfs_h *g,
const char *root)
>    if (STREQ (type, "linux") || STREQ (type, "hurd")) {
>      if (STREQ (package_format, "rpm")) {
>  #ifdef DB_DUMP
> -      ret = list_applications_rpm (g, root);
> -      if (ret == NULL)
> -        return NULL;
> +      /* Allow db_dump to be missing at runtime so that it can be
> +       * installed as a weak dependency.
> +       */
> +      if (system (DB_DUMP " -V >/dev/null 2>&1") == 0)
{
> +        ret = list_applications_rpm (g, root);
> +        if (ret == NULL)
> +          return NULL;
> +      }
>  #endif

This approach has few issues:
a) DB_DUMP is not escaped, so a path with special characters will play
   badly with shell
b) `DB_DUMP -V` is executed every time RPM packages are extracted
c) there is no feedback to the users (not even a debug()) that DB_DUMP
   is not installed, and thus information on the installed RPM packages
   are not extracted
d) the same issue happens for the tools used to extract icons (netpbm,
   and icoutils)

I still do think my approach [1] is better in this regard, since it
already copes with all the points above.

Why should be optional tools searched at build time, hardcoded, and
then still need to be checked at runtime?  The concern that there is
no way to know which tools are used is sort of moot, since the internal
command API (in the library) logs program and arguments.

[1] https://www.redhat.com/archives/libguestfs/2017-February/msg00016.html

--
Pino Toscano