[Libguestfs] [PATCH 2/2] Use 'error' function for fprintf followed by exit.

Pino Toscano ptoscano at redhat.com
Mon Apr 4 13:06:52 UTC 2016


On Monday 04 April 2016 13:28:51 Richard W.M. Jones wrote:
> Like with the previous commit, this replaces instances of:
> 
>   if (something_bad) {
>     fprintf (stderr, "%s: error message\n", guestfs_int_program_name);
>     exit (EXIT_FAILURE);
>   }
> 
> with:
> 
>   if (something_bad)
>     error (EXIT_FAILURE, 0, "error message");
> 
> (except in a few cases were errno was incorrectly being ignored, in
> which case I have fixed that).
> 
> It's slightly more complex than the previous commit because we must be
> careful to:
> 
>  - Remove the program name (since error(3) prints it).
> 
>  - Remove any trailing \n character from the message.
> 
> Candidates for replacement were found using:
> 
>   pcregrep --buffer-size 10M -M '\bfprintf\b.*\n.*\bexit\b' `git ls-files`
> ---

Really nice improvement -- just a couple of notes.

> @@ -130,10 +131,8 @@ main (int argc, char *argv[])
>    int r;
>  
>    g = guestfs_create ();
> -  if (g == NULL) {
> -    fprintf (stderr, _("guestfs_create: failed to create handle\n"));
> -    exit (EXIT_FAILURE);
> -  }
> +  if (g == NULL)
> +    error (EXIT_FAILURE, errno, "guestfs_create");

What about

  error (EXIT_FAILURE, errno, _("failed to create handle"));

instead?  Also for all the occurrences of this change, in public tools
only (i.e. not for tests, nor p2v).

Something I noticed while reading the changes is that some of the error
messages end with period, while it seems most of them don't.  Should
all of them be without?

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/20160404/f4e63b8f/attachment.sig>


More information about the Libguestfs mailing list