[Libguestfs] [PATCH RFC supermin] ext2_initrd: error out if we can't add anything

Pino Toscano ptoscano at redhat.com
Fri Jul 22 08:53:14 UTC 2016


On Friday, 22 July 2016 15:59:58 CEST Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao at gmail.com>
> 
>   If we failed to add something to initrd, just error out.
> 
> Signed-off-by: Chen Hanxiao <chenhanxiao at gmail.com>
> ---
>  src/ext2_initrd.ml | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ext2_initrd.ml b/src/ext2_initrd.ml
> index d4a4e2f..d9a3a99 100644
> --- a/src/ext2_initrd.ml
> +++ b/src/ext2_initrd.ml
> @@ -151,8 +151,12 @@ let rec build_initrd debug tmpdir modpath initrd =
>    visit topset;
>    close_out chan;
>  
> +  let num_visted = StringSet.cardinal !visited in
>    if debug >= 1 then
> -    printf "supermin: ext2: wrote %d modules to minimal initrd\n%!" (StringSet.cardinal !visited);
> +    printf "supermin: ext2: wrote %d modules to minimal initrd\n%!" num_visted;
> +
> +  if num_visited == 0 then
> +    error "failed to write any modules into minimal initrd, try 'depmod -a'"
>  
>    (* This is the binary blob containing the init "script". *)
>    let init = binary_init () in

If the "visited" set is empty, most probably also "topset" was empty
too: for each module in "topset" there is at least one element added in
"visited" (the module itself).

Keeping into account also what Rich replied as well, I guess a warning
could be added earlier.

Thanks,
-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20160722/85fd653c/attachment.sig>


More information about the Libguestfs mailing list