[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [0/5] guestfish: detect stdout-write failure



Nearly any program that writes to standard output can
benefit from this sort of fix.

Without it, running e.g., ./guestfish --version > /dev/full
would exit successfully, even though it got ENOSPC
when writing to the full device.  That means regular
output redirected to a file on a full partition may also
fail to be written, and the error ignored.

  Before:
      $ guestfish --version > /dev/full
  After:
      $ ./guestfish --version > /dev/full
      /w/co/libguestfs/fish/.libs/lt-guestfish: write error: No space left on device

Obviously, including the absolute program name in the diagnostic is a bug.
It should be "guestfish", and there's already code to perform that
sanitization in the patch below.  It fixes everything except the glibc
global variable, program_invocation_name, used by error, called by
atexit+close_stdout.  I'll fix that via gnulib's progname module later
today or tomorrow.  Note that all other diagnostics (e.g., below) do
use the sanitized name.

The second patch is to make guestfish write --help output
to stdout, not stderr, per convention.  Also, since --help
output is pretty long, I find it clearer (e.g., when I misspell
an option) to write a brief diagnostic, like

    $ ./guestfish --fjd
    guestfish: unrecognized option '--fjd'
    Try `guestfish --help' for more information.
    [Exit 1]

The third patch is another small improvement: let getopt diagnose failures.
Before, using --mount with no option-argument would print a
misleading diagnostic:

    $ ./guestfish -m
    guestfish: unexpected command line option 0x3f
    ...all --help output...
    [Exit 1]

Now it prints this:

    $ ./guestfish -m
    guestfish: option requires an argument -- 'm'
    Try `guestfish --help' for more information.
    [Exit 1]

------------------------------
The fourth patch makes the Before/After change demonstrated above.

The last patch avoids new cpp macro redefinition warnings.
Now that we're using a few more gnulib modules, they
end up defining _GNU_SOURCE via a definition in config.h,
so the explicit definitons in various *.c files evoke warnings.


$ wc -l 00*
   45 0001-build-avoid-some-autoconf-warnings.patch
  353 0002-guestfish-write-help-to-stdout-use-gnulib-s-progname.patch
   27 0003-guestfish-don-t-try-to-diagnose-getopt-failure.patch
   53 0004-guestfish-diagnose-stdout-write-failure.patch
   88 0005-build-don-t-define-_GNU_SOURCE-manually.patch
  566 total

$ diffstat 00*
 b/bootstrap        |    1
 b/configure.ac     |   11 ++--
 b/fish/Makefile.am |    3 -
 b/fish/destpaths.c |    2
 b/fish/fish.c      |  125 ++++++++++++++++++++++++++++++++++-------------------
 b/src/guestfs.c    |    2
 bootstrap          |    8 ++-
 fish/fish.c        |    9 +--
 8 files changed, 100 insertions(+), 61 deletions(-)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]