Update.
authorUlrich Drepper <drepper@redhat.com>
Wed, 25 Jul 2001 21:30:39 +0000 (21:30 +0000)
committerUlrich Drepper <drepper@redhat.com>
Wed, 25 Jul 2001 21:30:39 +0000 (21:30 +0000)
(write_output): Don't overwrite old cache file until we know we
have a new one.
* iconv/Makefile (install-sbin): Add iconvconfig.
* iconv/gconv_int.h: Add prototype for __gconv_release_cache.

ChangeLog
iconv/Makefile
iconv/iconvconfig.c

index bb4c383..b3117db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,8 +2,10 @@
 
        * iconv/iconvconfig.c (main): Don't write an output file if we
        have seen an error.
+       (write_output): Don't overwrite old cache file until we know we
+       have a new one.
 
-       * iconv/Makefile (install-bin): Add iconvconfig.
+       * iconv/Makefile (install-sbin): Add iconvconfig.
 
 2001-07-25  Jakub Jelinek  <jakub@redhat.com>
 
@@ -43,7 +45,7 @@
        __gconv_release_cache after the steps are handled.
        * iconv/gconv_dl.c (__gconv_find_shlib): Allocate file name in the
        record as well.
-       * iconv/gconv_int.h: Add prototype fpr __gconv_release_cache.
+       * iconv/gconv_int.h: Add prototype for __gconv_release_cache.
 
        * iconv/gconv_cache.c (__gconv_lookup_cache): Catch one more
        boundary case and reject it.
index 9945d98..28ba18d 100644 (file)
@@ -54,7 +54,7 @@ distribute    = gconv_builtin.h gconv_int.h loop.c skeleton.c iconv_prog.h \
 
 others         = iconv_prog iconvconfig
 install-others = $(inst_bindir)/iconv
-install-bin    = iconvconfig
+install-sbin   = iconvconfig
 
 CFLAGS-gconv_cache.c = -DGCONV_DIR='"$(gconvdir)"'
 CFLAGS-gconv_conf.c = -DGCONV_PATH='"$(gconvdir)"'
index 379a3bf..6959d94 100644 (file)
@@ -305,7 +305,7 @@ main (int argc, char *argv[])
   if (status == 0)
     status = write_output ();
   else
-    fputs ("No output written!\n", stderr);
+    error (1, 0, _("no output file produced because warning were issued"));
 
   return status;
 }
@@ -966,6 +966,7 @@ write_output (void)
   struct iovec iov[6];
   static const gidx_t null_word;
   size_t total;
+  char tmpfname[sizeof (GCONV_MODULES_CACHE) + strlen (".XXXXXX")];
 
   /* Function to insert the names.  */
   static void name_insert (const void *nodep, VISIT value, int level)
@@ -992,7 +993,8 @@ write_output (void)
     }
 
   /* Open the output file.  */
-  fd = open (GCONV_MODULES_CACHE, O_TRUNC | O_CREAT | O_RDWR, 0644);
+  strcpy (stpcpy (tmpfname, GCONV_MODULES_CACHE), ".XXXXXX");
+  fd = mkstemp (tmpfname);
   if (fd == -1)
     return 1;
 
@@ -1144,12 +1146,17 @@ write_output (void)
   total += iov[idx].iov_len;
   ++idx;
 
-  if (TEMP_FAILURE_RETRY (writev (fd, iov, idx)) != total)
+  if (TEMP_FAILURE_RETRY (writev (fd, iov, idx)) != total
+      /* The file was created with mode 0600.  Make it world-readable.  */
+      || fchmod (fd, 0644) != 0
+      /* Rename the file, possibly replacing an old one.  */
+      || rename (tmpfname, GCONV_MODULES_CACHE) != 0)
     {
       int save_errno = errno;
       close (fd);
-      unlink (GCONV_MODULES_CACHE);
-      error (EXIT_FAILURE, save_errno, gettext ("cannot write output file"));
+      unlink (tmpfname);
+      error (EXIT_FAILURE, save_errno,
+            gettext ("cannot generate output file"));
     }
 
   close (fd);