Bug 22292 - localedef exits with error 4 when it should be error 1
Summary: localedef exits with error 4 when it should be error 1
Alias: None
Product: glibc
Classification: Unclassified
Component: locale (show other bugs)
Version: 2.27
: P2 normal
Target Milestone: 2.27
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2017-10-13 08:11 UTC by Carlos O'Donell
Modified: 2017-10-16 18:31 UTC (History)
0 users

See Also:
Last reconfirmed:
fweimer: security-


Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2017-10-13 08:11:42 UTC
The current localedef implementation treats all warnings like errors.

This means that you can never have just warnings and an exit code of 1 as is required by POSIX.

The fix for this is for localdef to stop using error_message_count to count errors, and instead adopt some better internal structure to track issued errors, warnings, and verbose messages.

If any errors are seen, then exit with error 4 without writing data.

If only warnings are seen, then exit with error 1 to indicate data was written.
Comment 1 cvs-commit@gcc.gnu.org 2017-10-14 05:31:30 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  bc3821bb3b19646311d36c82a13b4ce5afea3508 (commit)
       via  a3e23a2c1d9e871545c6f438a41fcb8ad429cf70 (commit)
       via  f16491eb8ebbef402f3da6f4035ce70fe36dec97 (commit)
       via  8dc8be75d2afb7ebaf55f7609b301e5c6b8692e5 (commit)
      from  18c08b96414c7bb01af92bfef8d542ffc7bdaf80 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------

commit bc3821bb3b19646311d36c82a13b4ce5afea3508
Author: Carlos O'Donell <carlos@systemhalted.org>
Date:   Fri Oct 13 14:36:23 2017 -0700

    locale: No warning for non-symbolic character (bug 22295)
    In "Is it OK to write ASCII strings directly into locale source files?"
    https://sourceware.org/ml/libc-alpha/2017-07/msg00807.html there is
    universal consensus that we do not have to keep writing <Uxxxx> symbolic
    characters in locale files.
    Ulrich Drepper's historical comment was that symbolic characters were
    used for the eventuality of converting the source files to any encoding
    system. Fast forward to today and UTF-8 is the standard. So the
    requirement of <Uxxxx> is hard to justify.
    Zack Weinberg's excellent scripts are coming along we can use these to
    find instances of human errors in the scripts:
    It still won't be easy to distinguish from i for �, but that's still the
    case for <Uxxxx> characters which humans can't read either.
    Since we all agreed that we should be able to use non-symbolic (<Uxxxx>)
    characters in locale files, the following change removes the verbose
    warning that is raised if you use non-symbolic characters in the locale
    Signed-off-by: Carlos O'Donell <carlos@redhat.com>


commit a3e23a2c1d9e871545c6f438a41fcb8ad429cf70
Author: Carlos O'Donell <carlos@systemhalted.org>
Date:   Fri Oct 13 14:33:09 2017 -0700

    locale: Allow "" int_curr_Symbol (bug 22294)
    The builtin POSIX locale has "" as the international currency symbol,
    but a non-builtin locale may not have such a blank int_curr_symbol.
    Therefore to support non-builtin locales with similar "" int_curr_symbol
    we adjust the LC_MONETARY parser to allow the normal 4-character
    int_curr_symbol *and* the empty "" no symbol. Anything else remains
    Tested by building all the locales.  Tested also with a custom C.UTF-8
    locale with "" for int_curr_symbol.
    Signed-off-by: Carlos O'Donell <carlos@redhat.com>


commit f16491eb8ebbef402f3da6f4035ce70fe36dec97
Author: Carlos O'Donell <carlos@systemhalted.org>
Date:   Fri Oct 13 09:54:03 2017 -0700

    locale: Fix localedef exit code (Bug 22292)
    The error and warning handling in localedef, locale, and iconv
    is a bit of a mess.
    We use ugly constructs like this:
          WITH_CUR_LOCALE (error (1, errno, gettext ("\
    cannot read character map directory `%s'"), directory));
    to issue errors, and read error_message_count directly from the
    error API to detect errors. The problem with that is that the
    code also uses error to print warnings, and informative messages.
    All of this leads to problems where just having warnings will
    produce an exit status as-if errors had been seen.
    To fix this situation I have adopted the following high-level
    * All errors are counted distinctly.
    * All warnings are counted distinctly.
    * All informative messages are not counted.
    * Increasing verbosity cannot generate *more* errors, and
      it previously did for errors conditional on verbose,
      this is now fixed.
    * Increasing verbosity *can* generate *more* warnings.
    * Making the output quiet cannot generate *fewer* errors,
      and it previously did for errors conditional on be_quiet,
      this is now fixed.
    * Each of error, warning, and informative message has it's
      own function to call defined in record-status.h, and they
      are: record_error, record_warning, and record_verbose.
    * The record_error function always records an error, but
      conditional on be_quiet may not print it.
    * The record_warning function always records a warning,
      but conditional on be_quiet may not print it.
    * The record_verbose function only prints the verbose
      message if verbose is true and be_quiet is false.
    This has allowed the following fix:
    * Previously any warnings were being treated as errors
      because they incremented error_message_count, but now
      we properly return an exit status of 1 if there are
      warnings but output was generated.
    All of this allows localedef to correctly decide if errors,
    or warnings were present, and produce the correct exit code.
    The locale and iconv programs now also use record-status.h
    and we have removed the WITH_CUR_LOCALE hack, and instead
    have internal push_locale/pop_locale functions centralized
    in the record routines.
    Signed-off-by: Carlos O'Donell <carlos@redhat.com>


commit 8dc8be75d2afb7ebaf55f7609b301e5c6b8692e5
Author: Carlos O'Donell <carlos@systemhalted.org>
Date:   Thu Oct 12 23:52:14 2017 -0700

    localedata: Reorganize Unicode LC_CTYPE inclusion.
    The commit does the following things:
    * Move non-transliteration Unicode generated data to i18n_ctype.
    * Copy the i18n_ctype data into i18n and add transliteration.
    In the future, any locale which needs Unicode LC_CTYPE data can
    also just use `copy i18n_ctype` and get the base character classes
    and maps without transliteration.
    Tested by compiling all the locales and my prototype C.UTF-8 which
    uses it.
    Signed-off-by: Carlos O'Donell <carlos@redhat.com>


Summary of changes:
 ChangeLog                               |   82 ++
 locale/programs/charmap-dir.c           |    6 +-
 locale/programs/charmap.c               |   35 +-
 locale/programs/ld-address.c            |   90 +-
 locale/programs/ld-collate.c            |   64 +-
 locale/programs/ld-ctype.c              |  258 ++--
 locale/programs/ld-identification.c     |   24 +-
 locale/programs/ld-measurement.c        |   14 +-
 locale/programs/ld-messages.c           |   35 +-
 locale/programs/ld-monetary.c           |   69 +-
 locale/programs/ld-name.c               |   20 +-
 locale/programs/ld-numeric.c            |   23 +-
 locale/programs/ld-paper.c              |   14 +-
 locale/programs/ld-telephone.c          |   26 +-
 locale/programs/ld-time.c               |   97 +-
 locale/programs/linereader.c            |    8 -
 locale/programs/linereader.h            |   26 +-
 locale/programs/locale.c                |    6 +-
 locale/programs/localedef.c             |   62 +-
 locale/programs/localedef.h             |   18 +-
 locale/programs/locarchive.c            |    4 +-
 locale/programs/locfile.c               |   15 +-
 locale/programs/record-status.h         |  227 +++
 locale/programs/repertoire.c            |   11 +-
 localedata/gen-locale.sh                |   26 +-
 localedata/locales/i18n                 | 2297 +------------------------------
 localedata/locales/{i18n => i18n_ctype} |  385 +-----
 localedata/tst-fmon.sh                  |   19 +-
 localedata/tst-locale.sh                |   19 +-
 localedata/unicode-gen/Makefile         |   26 +-
 30 files changed, 822 insertions(+), 3184 deletions(-)
 create mode 100644 locale/programs/record-status.h
 copy localedata/locales/{i18n => i18n_ctype} (91%)
Comment 2 Carlos O'Donell 2017-10-14 05:32:18 UTC