localedef: Add verbose messages for failure paths.

Message ID 9ce1738a-1830-67d8-cad8-b8bec4963f03@redhat.com
State New, archived
Headers

Commit Message

Carlos O'Donell Dec. 11, 2018, 1:19 a.m. UTC
  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 <carlos@redhat.com>
---
 ChangeLog                   |  5 +++++
 locale/programs/localedef.c | 30 ++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 8 deletions(-)
  

Patch

diff --git a/ChangeLog b/ChangeLog
index 8d2494e054..0fd6dfc224 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@ 
+2018-12-10  Carlos O'Donell  <carlos@redhat.com>
+
+	* locale/programs/localedef.c (construct_output_path): Use
+	record_verbose to print verbose output in three failure modes.
+
 2018-12-10  Joseph Myers  <joseph@codesourcery.com>
 
 	* scripts/gen-as-const.py (main): Handle --python option.
diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 6c4936be6b..10c08231fe 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -526,7 +526,11 @@  construct_output_path (char *path)
 		      (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 @@  construct_output_path (char *path)
   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';