[review] localedef: Add verbose messages for failure paths.

classic Classic list List threaded Threaded
30 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[review] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................

localedef: Add verbose messages for failure paths.

During testing of localedef running in a minimal container
there were several error cases which were hard to diagnose
since they appeared as strerror (errno) values printed by
the higher level functions.  This change adds three new
verbose messages for potential failure paths.  The new
messages give the user the opportunity to use -v and display
additional information about why localedef might be failing.
I found these messages useful myself while writing a localedef
container test for --no-hard-links.

Signed-off-by: Carlos O'Donell <[hidden email]>
Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
---
M locale/programs/localedef.c
1 file changed, 22 insertions(+), 8 deletions(-)



diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 3dcf15f..965751f 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -526,7 +526,11 @@
       (int) (startp - path), path, normal, endp, '\0');
 
       if (n < 0)
- return NULL;
+ {
+  record_verbose (stderr,
+  _("failed to allocate space for compiled locale path"));
+  return NULL;
+ }
 
       endp = result + n - 1;
     }
@@ -546,13 +550,23 @@
   errno = 0;
 
   if (no_archive && euidaccess (result, W_OK) == -1)
-    /* Perhaps the directory does not exist now.  Try to create it.  */
-    if (errno == ENOENT)
-      {
- errno = 0;
- if (mkdir (result, 0777) < 0)
-  return NULL;
-      }
+    {
+      /* Perhaps the directory does not exist now.  Try to create it.  */
+      if (errno == ENOENT)
+ {
+  errno = 0;
+  if (mkdir (result, 0777) < 0)
+    {
+      record_verbose (stderr,
+      _("cannot create output path \"%s\": %s"),
+      result, strerror (errno));
+      return NULL;
+    }
+ }
+      else
+ record_verbose (stderr, _("no write permission to output path: %s"),
+ strerror (errno));
+    }
 
   *endp++ = '/';
   *endp = '\0';

--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 1
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-MessageType: newchange
Reply | Threaded
Open this post in threaded view
|

[review] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
Florian Weimer has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 1:

(3 comments)

I like the direction of this change, but there are some nits.

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1//COMMIT_MSG 
Commit Message:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1//COMMIT_MSG@19 
PS1, Line 19: Signed-off-by: Carlos O'Donell <[hidden email]>
We do not use DCO and Signed-off-by.


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c 
File locale/programs/localedef.c:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c@531 
PS1, Line 531:  _("failed to allocate space for compiled locale path"));
I think this line is too long.  I think we use xmalloc in many places already, so it would make sense to introduce xasprintf and use that consistently in the application.  (The version from support/ is not suitable in this context.)


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c@567 
PS1, Line 567: record_verbose (stderr, _("no write permission to output path: %s"),
Would it make sense to include the output path in this message as well?



--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 1
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-Comment-Date: Thu, 24 Oct 2019 19:33:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

[review] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Florian Weimer has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 1: Code-Review+2


--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 1
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-Comment-Date: Thu, 24 Oct 2019 19:40:10 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

[review] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Florian Weimer has removed a vote from this change. ( https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303 )


Change subject: localedef: Add verbose messages for failure paths.
......................................................................


Removed Code-Review+2 by Florian Weimer <[hidden email]>
--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 1
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-MessageType: deleteVote
Reply | Threaded
Open this post in threaded view
|

[review v2] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................

localedef: Add verbose messages for failure paths.

During testing of localedef running in a minimal container
there were several error cases which were hard to diagnose
since they appeared as strerror (errno) values printed by
the higher level functions.  This change adds three new
verbose messages for potential failure paths.  The new
messages give the user the opportunity to use -v and display
additional information about why localedef might be failing.
I found these messages useful myself while writing a localedef
container test for --no-hard-links.

Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
---
A include/programs/xasprintf.h
M locale/Makefile
M locale/programs/localedef.c
M locale/programs/localedef.h
A locale/programs/xasprintf.c
5 files changed, 86 insertions(+), 25 deletions(-)



diff --git a/include/programs/xasprintf.h b/include/programs/xasprintf.h
new file mode 100644
index 0000000..c2de4e7
--- /dev/null
+++ b/include/programs/xasprintf.h
@@ -0,0 +1,23 @@
+/* asprintf with out of memory checking
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef _XASPRINTF_H
+#define _XASPRINTF_H 1
+
+extern int xasprintf (char **string_ptr, const char *format, ...);
+
+#endif /* xasprintf.h */
diff --git a/locale/Makefile b/locale/Makefile
index 1a19b6f..943df35 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -56,7 +56,7 @@
 localedef-aux := md5
 locale-modules := locale locale-spec
 lib-modules := charmap-dir simple-hash xmalloc xstrdup \
-   record-status
+   record-status xasprintf
 
 
 GPERF = gperf
diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 3dcf15f..30bc038 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -434,20 +434,15 @@
     {
     case ARGP_KEY_HELP_EXTRA:
       /* We print some extra information.  */
-      if (asprintf (&tp, gettext ("\
+      xasprintf (&tp, gettext ("\
 For bug reporting instructions, please see:\n\
-%s.\n"), REPORT_BUGS_TO) < 0)
- return NULL;
-      if (asprintf (&cp, gettext ("\
+%s.\n"), REPORT_BUGS_TO);
+      xasprintf (&cp, gettext ("\
 System's directory for character maps : %s\n\
        repertoire maps: %s\n\
        locale path    : %s\n\
 %s"),
-    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp) < 0)
- {
-  free (tp);
-  return NULL;
- }
+    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp);
       return cp;
     default:
       break;
@@ -518,15 +513,12 @@
  '/'.  */
       ssize_t n;
       if (normal == NULL)
- n = asprintf (&result, "%s%s/%s%c", output_prefix ?: "",
-      COMPLOCALEDIR, path, '\0');
+ n = xasprintf (&result, "%s%s/%s%c", output_prefix ?: "",
+       COMPLOCALEDIR, path, '\0');
       else
- n = asprintf (&result, "%s%s/%.*s%s%s%c",
-      output_prefix ?: "", COMPLOCALEDIR,
-      (int) (startp - path), path, normal, endp, '\0');
-
-      if (n < 0)
- return NULL;
+ n = xasprintf (&result, "%s%s/%.*s%s%s%c",
+       output_prefix ?: "", COMPLOCALEDIR,
+       (int) (startp - path), path, normal, endp, '\0');
 
       endp = result + n - 1;
     }
@@ -546,13 +538,23 @@
   errno = 0;
 
   if (no_archive && euidaccess (result, W_OK) == -1)
-    /* Perhaps the directory does not exist now.  Try to create it.  */
-    if (errno == ENOENT)
-      {
- errno = 0;
- if (mkdir (result, 0777) < 0)
-  return NULL;
-      }
+    {
+      /* Perhaps the directory does not exist now.  Try to create it.  */
+      if (errno == ENOENT)
+ {
+  errno = 0;
+  if (mkdir (result, 0777) < 0)
+    {
+      record_verbose (stderr,
+      _("cannot create output path \"%s\": %s"),
+      result, strerror (errno));
+      return NULL;
+    }
+ }
+      else
+ record_verbose (stderr, _("no write permission to output path: %s"),
+ strerror (errno));
+    }
 
   *endp++ = '/';
   *endp = '\0';
diff --git a/locale/programs/localedef.h b/locale/programs/localedef.h
index 80da0b0..ad2a927 100644
--- a/locale/programs/localedef.h
+++ b/locale/programs/localedef.h
@@ -123,6 +123,7 @@
 
 /* Prototypes for a few program-wide used functions.  */
 #include <programs/xmalloc.h>
+#include <programs/xasprintf.h>
 
 
 /* Mark given locale as to be read.  */
diff --git a/locale/programs/xasprintf.c b/locale/programs/xasprintf.c
new file mode 100644
index 0000000..07b18d1
--- /dev/null
+++ b/locale/programs/xasprintf.c
@@ -0,0 +1,35 @@
+/* asprintf with out of memory checking
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <libintl.h>
+#include <error.h>
+
+int
+xasprintf (char **string_ptr, const char *format, ...)
+{
+  va_list arg;
+  int ret;
+  va_start (arg, format);
+  ret = vasprintf (string_ptr, format, arg);
+  if (ret == -1)
+    error (EXIT_FAILURE, 0, _("memory exhausted"));
+  va_end (arg);
+  return ret;
+}

--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 2
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-MessageType: newpatchset
Reply | Threaded
Open this post in threaded view
|

[review v2] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Carlos O'Donell has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 2:

> Patch Set 1:
>
> (3 comments)
>
> I like the direction of this change, but there are some nits.

v2 pushed with your changes resolved.
- Used xasprintf
- Fixed commit message.


--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 2
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-Comment-Date: Fri, 25 Oct 2019 02:31:21 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

[review v2] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Florian Weimer has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 2:

(4 comments)

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/2/include/programs/xasprintf.h 
File include/programs/xasprintf.h:

PS2:
Should this go into xmalloc.h?


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/2/include/programs/xasprintf.h@21 
PS2, Line 21: extern int xasprintf (char **string_ptr, const char *format, ...);
This needs a format attribute.  The prototype in gnulib (and support/) looks like this:

char *xasprintf (const char *format, ...);

I think we should follow that, even though we actually use the returned length in the code today.


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/2/locale/programs/localedef.c 
File locale/programs/localedef.c:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/2/locale/programs/localedef.c@446 
PS2, Line 446:       return cp;
Can you fix the memory leak for tp, too?


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/2/locale/programs/localedef.c@559 
PS2, Line 559:   *endp++ = '/';
Maybe it would be clearer to add the slash with another xasprintf call at the end, not do the fancy in-place manipulation of the string.



--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 2
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-Comment-Date: Fri, 25 Oct 2019 06:42:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

[review v2] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Florian Weimer has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 2:

Please drop the dependent patch in v3.


--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 2
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-Comment-Date: Fri, 25 Oct 2019 13:14:05 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

[review v3] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................

localedef: Add verbose messages for failure paths.

During testing of localedef running in a minimal container
there were several error cases which were hard to diagnose
since they appeared as strerror (errno) values printed by
the higher level functions.  This change adds three new
verbose messages for potential failure paths.  The new
messages give the user the opportunity to use -v and display
additional information about why localedef might be failing.
I found these messages useful myself while writing a localedef
container test for --no-hard-links.

Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
---
A include/programs/xasprintf.h
M locale/Makefile
M locale/programs/localedef.c
M locale/programs/localedef.h
A locale/programs/xasprintf.c
5 files changed, 86 insertions(+), 25 deletions(-)



diff --git a/include/programs/xasprintf.h b/include/programs/xasprintf.h
new file mode 100644
index 0000000..c2de4e7
--- /dev/null
+++ b/include/programs/xasprintf.h
@@ -0,0 +1,23 @@
+/* asprintf with out of memory checking
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef _XASPRINTF_H
+#define _XASPRINTF_H 1
+
+extern int xasprintf (char **string_ptr, const char *format, ...);
+
+#endif /* xasprintf.h */
diff --git a/locale/Makefile b/locale/Makefile
index 1a19b6f..943df35 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -56,7 +56,7 @@
 localedef-aux := md5
 locale-modules := locale locale-spec
 lib-modules := charmap-dir simple-hash xmalloc xstrdup \
-   record-status
+   record-status xasprintf
 
 
 GPERF = gperf
diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 3dcf15f..30bc038 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -434,20 +434,15 @@
     {
     case ARGP_KEY_HELP_EXTRA:
       /* We print some extra information.  */
-      if (asprintf (&tp, gettext ("\
+      xasprintf (&tp, gettext ("\
 For bug reporting instructions, please see:\n\
-%s.\n"), REPORT_BUGS_TO) < 0)
- return NULL;
-      if (asprintf (&cp, gettext ("\
+%s.\n"), REPORT_BUGS_TO);
+      xasprintf (&cp, gettext ("\
 System's directory for character maps : %s\n\
        repertoire maps: %s\n\
        locale path    : %s\n\
 %s"),
-    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp) < 0)
- {
-  free (tp);
-  return NULL;
- }
+    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp);
       return cp;
     default:
       break;
@@ -518,15 +513,12 @@
  '/'.  */
       ssize_t n;
       if (normal == NULL)
- n = asprintf (&result, "%s%s/%s%c", output_prefix ?: "",
-      COMPLOCALEDIR, path, '\0');
+ n = xasprintf (&result, "%s%s/%s%c", output_prefix ?: "",
+       COMPLOCALEDIR, path, '\0');
       else
- n = asprintf (&result, "%s%s/%.*s%s%s%c",
-      output_prefix ?: "", COMPLOCALEDIR,
-      (int) (startp - path), path, normal, endp, '\0');
-
-      if (n < 0)
- return NULL;
+ n = xasprintf (&result, "%s%s/%.*s%s%s%c",
+       output_prefix ?: "", COMPLOCALEDIR,
+       (int) (startp - path), path, normal, endp, '\0');
 
       endp = result + n - 1;
     }
@@ -546,13 +538,23 @@
   errno = 0;
 
   if (no_archive && euidaccess (result, W_OK) == -1)
-    /* Perhaps the directory does not exist now.  Try to create it.  */
-    if (errno == ENOENT)
-      {
- errno = 0;
- if (mkdir (result, 0777) < 0)
-  return NULL;
-      }
+    {
+      /* Perhaps the directory does not exist now.  Try to create it.  */
+      if (errno == ENOENT)
+ {
+  errno = 0;
+  if (mkdir (result, 0777) < 0)
+    {
+      record_verbose (stderr,
+      _("cannot create output path \"%s\": %s"),
+      result, strerror (errno));
+      return NULL;
+    }
+ }
+      else
+ record_verbose (stderr, _("no write permission to output path: %s"),
+ strerror (errno));
+    }
 
   *endp++ = '/';
   *endp = '\0';
diff --git a/locale/programs/localedef.h b/locale/programs/localedef.h
index 80da0b0..ad2a927 100644
--- a/locale/programs/localedef.h
+++ b/locale/programs/localedef.h
@@ -123,6 +123,7 @@
 
 /* Prototypes for a few program-wide used functions.  */
 #include <programs/xmalloc.h>
+#include <programs/xasprintf.h>
 
 
 /* Mark given locale as to be read.  */
diff --git a/locale/programs/xasprintf.c b/locale/programs/xasprintf.c
new file mode 100644
index 0000000..07b18d1
--- /dev/null
+++ b/locale/programs/xasprintf.c
@@ -0,0 +1,35 @@
+/* asprintf with out of memory checking
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <libintl.h>
+#include <error.h>
+
+int
+xasprintf (char **string_ptr, const char *format, ...)
+{
+  va_list arg;
+  int ret;
+  va_start (arg, format);
+  ret = vasprintf (string_ptr, format, arg);
+  if (ret == -1)
+    error (EXIT_FAILURE, 0, _("memory exhausted"));
+  va_end (arg);
+  return ret;
+}

--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 3
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-MessageType: newpatchset
Reply | Threaded
Open this post in threaded view
|

[review v3] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Carlos O'Donell has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 3:

(3 comments)

I've resolved 2/3 issues here, I'll fix the rest in v4.

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1//COMMIT_MSG 
Commit Message:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1//COMMIT_MSG@19 
PS1, Line 19: Signed-off-by: Carlos O'Donell <[hidden email]>
> We do not use DCO and Signed-off-by.
Done


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c 
File locale/programs/localedef.c:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c@531 
PS1, Line 531:  _("failed to allocate space for compiled locale path"));
> I think this line is too long. […]
Done


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c@567 
PS1, Line 567: record_verbose (stderr, _("no write permission to output path: %s"),
> Would it make sense to include the output path in this message as well?
This isn't resolved yet.



--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 3
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-Comment-Date: Fri, 25 Oct 2019 13:25:57 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Florian Weimer <[hidden email]>
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

Re: [review v3] localedef: Add verbose messages for failure paths.

Joseph Myers
On Fri, 25 Oct 2019, Carlos O'Donell (Code Review) wrote:

> https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c@531 
> PS1, Line 531:  _("failed to allocate space for compiled locale path"));
> > I think this line is too long. […]
> Done

This is a meta-comment on the formatting of these emails and a test of
email replies to gerrit:

"PS1, Line 531:" is not helpful, and just makes the lines in these
messages longer.  Quoted text should just use normal "> " to quote it
(with the additional leading character "+", "-" or " " when being quoted
as part of a diff hunk).

--
Joseph S. Myers
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [review v3] localedef: Add verbose messages for failure paths.

Carlos O'Donell-6
On 10/25/19 10:56 AM, Joseph Myers wrote:

> On Fri, 25 Oct 2019, Carlos O'Donell (Code Review) wrote:
>
>> https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c@531 
>> PS1, Line 531:  _("failed to allocate space for compiled locale path"));
>>> I think this line is too long. […]
>> Done
>
> This is a meta-comment on the formatting of these emails and a test of
> email replies to gerrit:
>
> "PS1, Line 531:" is not helpful, and just makes the lines in these
> messages longer.  Quoted text should just use normal "> " to quote it
> (with the additional leading character "+", "-" or " " when being quoted
> as part of a diff hunk).
>

Right, I think this falls under the "show more context" issue.

In this response I'm marking a comment as "Done" and I probably should
have said more. I removed the entire line in v2 of the patch, so if you
fetch v2 you'll see it's gone and I'm using xasprintf.

--
Cheers,
Carlos.
Reply | Threaded
Open this post in threaded view
|

Re: [review v3] localedef: Add verbose messages for failure paths.

Joseph Myers
In reply to this post by Sourceware to Gerrit sync (Code Review)
On Fri, 25 Oct 2019, Carlos O'Donell (Code Review) wrote:

> https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/1/locale/programs/localedef.c@531 
> PS1, Line 531:  _("failed to allocate space for compiled locale path"));
> > I think this line is too long. […]
> Done

Having previously sent a meta-comment and got an email bounce from gerrit,
testing whether having now set up an account on gerrit makes it any better
at understanding emails sent to it and adding them to the appropriate
issues.

--
Joseph S. Myers
[hidden email]
Reply | Threaded
Open this post in threaded view
|

[review v3] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Simon Marchi has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 3:

(2 comments)

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/3/locale/programs/localedef.c 
File locale/programs/localedef.c:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/3/locale/programs/localedef.c@437 
PS3, Line 437:
428 | more_help (int key, const char *text, void *input)
429 | {
430 |   char *cp;
431 |   char *tp;
432 |
433 |   switch (key)
434 |     {
435 |     case ARGP_KEY_HELP_EXTRA:
436 |       /* We print some extra information.  */
437 |       xasprintf (&tp, gettext ("\

Hi Carlos (1).


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/3/locale/programs/localedef.c@521 
PS3, Line 521:
479 | construct_output_path (char *path)
    | ...
512 | the end of the function we need another byte for the trailing
513 | '/'.  */
514 |       ssize_t n;
515 |       if (normal == NULL)
516 | n = xasprintf (&result, "%s%s/%s%c", output_prefix ?: "",
517 |       COMPLOCALEDIR, path, '\0');
518 |       else
519 | n = xasprintf (&result, "%s%s/%.*s%s%s%c",
520 |       output_prefix ?: "", COMPLOCALEDIR,
521 |       (int) (startp - path), path, normal, endp, '\0');

Hi Carlos (2).



--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 3
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-CC: Simon Marchi <[hidden email]>
Gerrit-Comment-Date: Sun, 27 Oct 2019 15:44:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

[review v3] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Florian Weimer has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 3:

(2 comments)

Mark test comments as done.

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/3/locale/programs/localedef.c 
File locale/programs/localedef.c:

https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/3/locale/programs/localedef.c@437 
PS3, Line 437:
428 | more_help (int key, const char *text, void *input)
    | ...
432 |
433 |   switch (key)
434 |     {
435 |     case ARGP_KEY_HELP_EXTRA:
436 |       /* We print some extra information.  */
437 >       xasprintf (&tp, gettext ("\
438 | For bug reporting instructions, please see:\n\
439 | %s.\n"), REPORT_BUGS_TO);
440 |       xasprintf (&cp, gettext ("\
441 | System's directory for character maps : %s\n\
442 |       repertoire maps: %s\n\

> Hi Carlos (1).

Done


https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303/3/locale/programs/localedef.c@521 
PS3, Line 521:
479 | construct_output_path (char *path)
    | ...
516 | n = xasprintf (&result, "%s%s/%s%c", output_prefix ?: "",
517 |       COMPLOCALEDIR, path, '\0');
518 |       else
519 | n = xasprintf (&result, "%s%s/%.*s%s%s%c",
520 |       output_prefix ?: "", COMPLOCALEDIR,
521 >       (int) (startp - path), path, normal, endp, '\0');
522 |
523 |       endp = result + n - 1;
524 |     }
525 |   else
526 |     {

> Hi Carlos (2).

Done



--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 3
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-CC: Simon Marchi <[hidden email]>
Gerrit-Comment-Date: Thu, 07 Nov 2019 09:01:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Simon Marchi <[hidden email]>
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

[review v4] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................

localedef: Add verbose messages for failure paths.

During testing of localedef running in a minimal container
there were several error cases which were hard to diagnose
since they appeared as strerror (errno) values printed by
the higher level functions.  This change adds three new
verbose messages for potential failure paths.  The new
messages give the user the opportunity to use -v and display
additional information about why localedef might be failing.
I found these messages useful myself while writing a localedef
container test for --no-hard-links.

Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
---
A include/programs/xasprintf.h
M locale/Makefile
M locale/programs/localedef.c
M locale/programs/localedef.h
A locale/programs/xasprintf.c
5 files changed, 120 insertions(+), 52 deletions(-)



diff --git a/include/programs/xasprintf.h b/include/programs/xasprintf.h
new file mode 100644
index 0000000..53193ba
--- /dev/null
+++ b/include/programs/xasprintf.h
@@ -0,0 +1,24 @@
+/* asprintf with out of memory checking
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef _XASPRINTF_H
+#define _XASPRINTF_H 1
+
+extern char *xasprintf (const char *format, ...)
+    __attribute__ ((__format__ (__printf__, 1, 2), __warn_unused_result__));
+
+#endif /* xasprintf.h */
diff --git a/locale/Makefile b/locale/Makefile
index 1a19b6f..943df35 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -56,7 +56,7 @@
 localedef-aux := md5
 locale-modules := locale locale-spec
 lib-modules := charmap-dir simple-hash xmalloc xstrdup \
-   record-status
+   record-status xasprintf
 
 
 GPERF = gperf
diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 3dcf15f..b926117 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -434,20 +434,16 @@
     {
     case ARGP_KEY_HELP_EXTRA:
       /* We print some extra information.  */
-      if (asprintf (&tp, gettext ("\
+      tp = xasprintf (gettext ("\
 For bug reporting instructions, please see:\n\
-%s.\n"), REPORT_BUGS_TO) < 0)
- return NULL;
-      if (asprintf (&cp, gettext ("\
+%s.\n"), REPORT_BUGS_TO);
+      cp = xasprintf (gettext ("\
 System's directory for character maps : %s\n\
        repertoire maps: %s\n\
        locale path    : %s\n\
 %s"),
-    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp) < 0)
- {
-  free (tp);
-  return NULL;
- }
+    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp);
+      free (tp);
       return cp;
     default:
       break;
@@ -477,15 +473,13 @@
 }
 
 
-/* The parameter to localedef describes the output path.  If it does
-   contain a '/' character it is a relative path.  Otherwise it names the
-   locale this definition is for.  */
+/* The parameter to localedef describes the output path.  If it does contain a
+   '/' character it is a relative path.  Otherwise it names the locale this
+   definition is for.   The returned path must be freed by the caller. */
 static const char *
 construct_output_path (char *path)
 {
-  const char *normal = NULL;
   char *result;
-  char *endp;
 
   if (strchr (path, '/') == NULL)
     {
@@ -493,50 +487,44 @@
  contains a reference to the codeset.  This should be
  normalized.  */
       char *startp;
+      char *endp = NULL;
+      const char *normal = NULL;
 
       startp = path;
-      /* We must be prepared for finding a CEN name or a location of
- the introducing `.' where it is not possible anymore.  */
+      /* Either we have a '@' which starts a CEN name or '.' which starts the
+ codeset specification.  The CEN name starts with '@' and may also have
+ a codeset specification, but we do not normalize the string after '@'.
+ If we only find the codeset specification then we normalize only the codeset
+ specification (but not anything after a subsequent '@').  */
       while (*startp != '\0' && *startp != '@' && *startp != '.')
  ++startp;
       if (*startp == '.')
  {
   /* We found a codeset specification.  Now find the end.  */
   endp = ++startp;
+
+  /* Stop at the first '@', and don't normalize anything past that.  */
   while (*endp != '\0' && *endp != '@')
     ++endp;
 
   if (endp > startp)
     normal = normalize_codeset (startp, endp - startp);
  }
-      else
- /* This is to keep gcc quiet.  */
- endp = NULL;
 
-      /* We put an additional '\0' at the end of the string because at
- the end of the function we need another byte for the trailing
- '/'.  */
-      ssize_t n;
       if (normal == NULL)
- n = asprintf (&result, "%s%s/%s%c", output_prefix ?: "",
-      COMPLOCALEDIR, path, '\0');
+ result = xasprintf ("%s%s/%s/", output_prefix ?: "",
+    COMPLOCALEDIR, path);
       else
- n = asprintf (&result, "%s%s/%.*s%s%s%c",
-      output_prefix ?: "", COMPLOCALEDIR,
-      (int) (startp - path), path, normal, endp, '\0');
-
-      if (n < 0)
- return NULL;
-
-      endp = result + n - 1;
+ result = xasprintf ("%s%s/%.*s%s%s/",
+    output_prefix ?: "", COMPLOCALEDIR,
+    (int) (startp - path), path, normal, endp ?: "");
+      /* Free the allocated normalized codeset name.  */
+      free ((char *) normal);
     }
   else
     {
-      /* This is a user path.  Please note the additional byte in the
- memory allocation.  */
-      size_t len = strlen (path) + 1;
-      result = xmalloc (len + 1);
-      endp = mempcpy (result, path, len) - 1;
+      /* This is a user path.  */
+      result = xasprintf ("%s/", path);
 
       /* If the user specified an output path we cannot add the output
  to the archive.  */
@@ -546,24 +534,40 @@
   errno = 0;
 
   if (no_archive && euidaccess (result, W_OK) == -1)
-    /* Perhaps the directory does not exist now.  Try to create it.  */
-    if (errno == ENOENT)
-      {
- errno = 0;
- if (mkdir (result, 0777) < 0)
-  return NULL;
-      }
-
-  *endp++ = '/';
-  *endp = '\0';
+    {
+      /* Perhaps the directory does not exist now.  Try to create it.  */
+      if (errno == ENOENT)
+ {
+  errno = 0;
+  if (mkdir (result, 0777) < 0)
+    {
+      record_verbose (stderr,
+      _("cannot create output path \"%s\": %s"),
+      result, strerror (errno));
+      free (result);
+      return NULL;
+    }
+ }
+      else
+ record_verbose (stderr,
+ _("no write permission to output path \"%s\": %s"),
+ result, strerror (errno));
+    }
 
   return result;
 }
 
 
-/* Normalize codeset name.  There is no standard for the codeset
-   names.  Normalization allows the user to use any of the common
-   names.  */
+/* Normalize codeset name.  There is no standard for the codeset names.
+   Normalization allows the user to use any of the common names e.g. UTF-8,
+   utf-8, utf8, UTF8 etc.
+
+   We normalize using the following rules:
+   - Remove all non-alpha-numeric characters
+   - Lowercase all cahracters.
+   - If there are only digits assume it's an ISO standard and prefix with 'iso'
+
+   We return the normalized string which needs to be freed by free.  */
 static const char *
 normalize_codeset (const char *codeset, size_t name_len)
 {
@@ -573,6 +577,7 @@
   char *wp;
   size_t cnt;
 
+  /* Compute the length of only the alpha-numeric characters.  */
   for (cnt = 0; cnt < name_len; ++cnt)
     if (isalnum (codeset[cnt]))
       {
@@ -582,6 +587,8 @@
   only_digit = 0;
       }
 
+  /* If there were only digits we assume it's an ISO standard and we will
+     prefix with 'iso' so include space for that.  */
   retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1);
 
   if (retval != NULL)
@@ -592,6 +599,7 @@
  wp = retval;
 
       for (cnt = 0; cnt < name_len; ++cnt)
+ /* Lowercase all characters. */
  if (isalpha (codeset[cnt]))
   *wp++ = tolower (codeset[cnt]);
  else if (isdigit (codeset[cnt]))
@@ -600,6 +608,7 @@
       *wp = '\0';
     }
 
+  /* Return allocated and converted name for caller to free.  */
   return (const char *) retval;
 }
 
diff --git a/locale/programs/localedef.h b/locale/programs/localedef.h
index 80da0b0..ad2a927 100644
--- a/locale/programs/localedef.h
+++ b/locale/programs/localedef.h
@@ -123,6 +123,7 @@
 
 /* Prototypes for a few program-wide used functions.  */
 #include <programs/xmalloc.h>
+#include <programs/xasprintf.h>
 
 
 /* Mark given locale as to be read.  */
diff --git a/locale/programs/xasprintf.c b/locale/programs/xasprintf.c
new file mode 100644
index 0000000..efc91a9
--- /dev/null
+++ b/locale/programs/xasprintf.c
@@ -0,0 +1,34 @@
+/* asprintf with out of memory checking
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <libintl.h>
+#include <error.h>
+
+char *
+xasprintf (const char *format, ...)
+{
+  va_list ap;
+  va_start (ap, format);
+  char *result;
+  if (vasprintf (&result, format, ap) < 0)
+    error (EXIT_FAILURE, 0, _("memory exhausted"));
+  va_end (ap);
+  return result;
+}

--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 4
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-CC: Simon Marchi <[hidden email]>
Gerrit-MessageType: newpatchset
Reply | Threaded
Open this post in threaded view
|

[review v4] localedef: Add verbose messages for failure paths.

Sourceware to Gerrit sync (Code Review)
In reply to this post by Sourceware to Gerrit sync (Code Review)
Carlos O'Donell has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/glibc/+/303
......................................................................


Patch Set 4:

(9 comments)

I rewrote part of the handling of result to avoid the in-place editing like you suggested. I also noticed another memory leak. The normalized paths need to be freed by the caller and they were not (just like the tp leak). This is ready for review again.

| --- /dev/null
| +++ /COMMIT_MSG
| @@ -1,0 +10,11 @@ During testing of localedef running in a minimal container
| +there were several error cases which were hard to diagnose
| +since they appeared as strerror (errno) values printed by
| +the higher level functions.  This change adds three new
| +verbose messages for potential failure paths.  The new
| +messages give the user the opportunity to use -v and display
| +additional information about why localedef might be failing.
| +I found these messages useful myself while writing a localedef
| +container test for --no-hard-links.
| +
| +Signed-off-by: Carlos O'Donell <[hidden email]>

PS1, Line 19:

Done

| +Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
| --- locale/programs/localedef.c
| +++ locale/programs/localedef.c
| @@ -523,14 +523,18 @@ construct_output_path (char *path)
|        else
|   n = asprintf (&result, "%s%s/%.*s%s%s%c",
|        output_prefix ?: "", COMPLOCALEDIR,
|        (int) (startp - path), path, normal, endp, '\0');
|  
|        if (n < 0)
| - return NULL;
| + {
| +  record_verbose (stderr,
| +  _("failed to allocate space for compiled locale path"));

PS1, Line 531:

Done

| +  return NULL;
| + }
|  
|        endp = result + n - 1;
|      }
|    else
|      {
|        /* This is a user path.  Please note the additional byte in the
|   memory allocation.  */

 ...

| @@ -556,7 +558,19 @@ construct_output_path (char *path)
| +  if (mkdir (result, 0777) < 0)
| +    {
| +      record_verbose (stderr,
| +      _("cannot create output path \"%s\": %s"),
| +      result, strerror (errno));
| +      return NULL;
| +    }
| + }
| +      else
| + record_verbose (stderr, _("no write permission to output path: %s"),

PS1, Line 567:

This is resolved. I added the output path.

| + strerror (errno));
| +    }
|  
|    *endp++ = '/';
|    *endp = '\0';
|  
|    return result;
|  }
|  
| --- /dev/null
| +++ include/programs/xasprintf.h
PS2:

I like having it distinct. Just a preference.

| @@ -1,0 +12,12 @@ /* asprintf with out of memory checking
| +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
| +   GNU General Public License for more details.
| +
| +   You should have received a copy of the GNU General Public License
| +   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
| +
| +#ifndef _XASPRINTF_H
| +#define _XASPRINTF_H 1
| +
| +extern int xasprintf (char **string_ptr, const char *format, ...);

PS2, Line 21:

Done

| +
| +#endif /* xasprintf.h */
| --- locale/programs/localedef.c
| +++ locale/programs/localedef.c
| @@ -443,18 +442,14 @@ System's directory for character maps : %s\n\
|         repertoire maps: %s\n\
|         locale path    : %s\n\
|  %s"),
| -    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp) < 0)
| - {
| -  free (tp);
| -  return NULL;
| - }
| +    CHARMAP_PATH, REPERTOIREMAP_PATH, LOCALE_PATH, tp);
|        return cp;

PS2, Line 446:

Done

|      default:
|        break;
|      }
|    return (char *) text;
|  }
|  
|  /* Print the version information.  */
|  static void
|  print_version (FILE *stream, struct argp_state *state)

 ...

| @@ -556,11 +550,19 @@ construct_output_path (char *path)
| +      result, strerror (errno));
| +      return NULL;
| +    }
| + }
| +      else
| + record_verbose (stderr, _("no write permission to output path: %s"),
| + strerror (errno));
| +    }
|  
|    *endp++ = '/';

PS2, Line 559:

Done

|    *endp = '\0';
|  
|    return result;
|  }
|  
|  
|  /* Normalize codeset name.  There is no standard for the codeset
|     names.  Normalization allows the user to use any of the common
|     names.  */
| --- locale/programs/localedef.c
| +++ locale/programs/localedef.c
| @@ -429,16 +429,15 @@ more_help (int key, const char *text, void *input)
|  {
|    char *cp;
|    char *tp;
|  
|    switch (key)
|      {
|      case ARGP_KEY_HELP_EXTRA:
|        /* We print some extra information.  */
| -      if (asprintf (&tp, gettext ("\
| +      xasprintf (&tp, gettext ("\

PS3, Line 437:

Done

|  For bug reporting instructions, please see:\n\
| -%s.\n"), REPORT_BUGS_TO) < 0)
| - return NULL;
| -      if (asprintf (&cp, gettext ("\
| +%s.\n"), REPORT_BUGS_TO);
| +      xasprintf (&cp, gettext ("\
|  System's directory for character maps : %s\n\
|         repertoire maps: %s\n\
|         locale path    : %s\n\

 ...

| @@ -523,16 +518,13 @@ construct_output_path (char *path)
|        else
| - n = asprintf (&result, "%s%s/%.*s%s%s%c",
| -      output_prefix ?: "", COMPLOCALEDIR,
| -      (int) (startp - path), path, normal, endp, '\0');
| -
| -      if (n < 0)
| - return NULL;
| + n = xasprintf (&result, "%s%s/%.*s%s%s%c",
| +       output_prefix ?: "", COMPLOCALEDIR,
| +       (int) (startp - path), path, normal, endp, '\0');

PS3, Line 521:

Done

|  
|        endp = result + n - 1;
|      }
|    else
|      {
|        /* This is a user path.  Please note the additional byte in the
|   memory allocation.  */
|        size_t len = strlen (path) + 1;
|        result = xmalloc (len + 1);

--
Gerrit-Project: glibc
Gerrit-Branch: master
Gerrit-Change-Id: I28b9f680711ff00252a2cb15625b774cc58ecb9d
Gerrit-Change-Number: 303
Gerrit-PatchSet: 4
Gerrit-Owner: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Carlos O'Donell <[hidden email]>
Gerrit-Reviewer: Florian Weimer <[hidden email]>
Gerrit-CC: Simon Marchi <[hidden email]>
Gerrit-Comment-Date: Tue, 10 Dec 2019 21:18:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Florian Weimer <[hidden email]>
Comment-In-Reply-To: Carlos O'Donell <[hidden email]>
Comment-In-Reply-To: Simon Marchi <[hidden email]>
Gerrit-MessageType: comment
Reply | Threaded
Open this post in threaded view
|

Re: [review v4] localedef: Add verbose messages for failure paths.

DJ Delorie-2
In reply to this post by Sourceware to Gerrit sync (Code Review)
"Carlos O'Donell (Code Review)" <[hidden email]>
writes:
> A locale/programs/xasprintf.c

We already have one in support/xasprintf.c.  We shouldn't have two
copies in the tree, somehow.

Reply | Threaded
Open this post in threaded view
|

Re: [review v4] localedef: Add verbose messages for failure paths.

Carlos O'Donell-6
On 12/10/19 4:34 PM, DJ Delorie wrote:
> "Carlos O'Donell (Code Review)" <[hidden email]>
> writes:
>> A locale/programs/xasprintf.c
>
> We already have one in support/xasprintf.c.  We shouldn't have two
> copies in the tree, somehow.

This was discussed originally, and we can't or rather don't want to
use the support/xasprintf.c since it may need to be built differently
from what we need for a distributed binary.

I would like to keep support/* infrastructure directly decoupled from
the installed programs we build.

Yes that means having possibly two xmalloc's and two xasprintf's.

For example the runtime implementation needs gettext and translation
for the error message, and calls error.

The support implementation doesn't need translations and can include
a bunch more headers and use FAIL_EXIT1.

I would really like to consider them distinct implementation for
distinct operating environments.

--
Cheers,
Carlos.

Reply | Threaded
Open this post in threaded view
|

Re: [review v4] localedef: Add verbose messages for failure paths.

Florian Weimer-5
* Carlos O'Donell:

> On 12/10/19 4:34 PM, DJ Delorie wrote:
>> "Carlos O'Donell (Code Review)" <[hidden email]>
>> writes:
>>> A locale/programs/xasprintf.c
>>
>> We already have one in support/xasprintf.c.  We shouldn't have two
>> copies in the tree, somehow.
>
> This was discussed originally, and we can't or rather don't want to
> use the support/xasprintf.c since it may need to be built differently
> from what we need for a distributed binary.
>
> I would like to keep support/* infrastructure directly decoupled from
> the installed programs we build.
>
> Yes that means having possibly two xmalloc's and two xasprintf's.
>
> For example the runtime implementation needs gettext and translation
> for the error message, and calls error.
>
> The support implementation doesn't need translations and can include
> a bunch more headers and use FAIL_EXIT1.
>
> I would really like to consider them distinct implementation for
> distinct operating environments.

I agree.  It's not ideal, but there isn't that much commonality between
the implementations anyway.

Florian

12