Fix data-loss with --version.
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Nov 2012 17:29:52 +0000 (09:29 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Nov 2012 17:29:52 +0000 (09:29 -0800)
* emacs.c (close_output_streams): Use strerror, not emacs_strerror,
as we can't assume that emacs_strerror is initialized, and strerror
is good enough here.
(main): Invoke atexit earlier, to catch earlier instances of
sending data to stdout and exiting, e.g., "emacs --version >/dev/full".

Fixes: debbugs:9574

src/ChangeLog
src/emacs.c

index b30b216..3356c98 100644 (file)
@@ -1,3 +1,12 @@
+2012-11-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Fix data-loss with --version (Bug#9574).
+       * emacs.c (close_output_streams): Use strerror, not emacs_strerror,
+       as we can't assume that emacs_strerror is initialized, and strerror
+       is good enough here.
+       (main): Invoke atexit earlier, to catch earlier instances of
+       sending data to stdout and exiting, e.g., "emacs --version >/dev/full".
+
 2012-11-04  Michael Marchionna  <tralfaz@pacbell.net>
 
        * nsterm.m: Add NSClearLineFunctionKey and keypad keys (Bug#8680).
index 6588bcd..061c4b4 100644 (file)
@@ -684,7 +684,7 @@ close_output_streams (void)
   if (close_stream (stdout) != 0)
     {
       fprintf (stderr, "Write error to standard output: %s\n",
-              emacs_strerror (errno));
+              strerror (errno));
       fflush (stderr);
       _exit (EXIT_FAILURE);
     }
@@ -748,6 +748,8 @@ main (int argc, char **argv)
     unexec_init_emacs_zone ();
 #endif
 
+  atexit (close_output_streams);
+
   sort_args (argc, argv);
   argc = 0;
   while (argv[argc]) argc++;
@@ -907,8 +909,6 @@ main (int argc, char **argv)
   if (do_initial_setlocale)
     setlocale (LC_ALL, "");
 
-  atexit (close_output_streams);
-
   inhibit_window_system = 0;
 
   /* Handle the -t switch, which specifies filename to use as terminal.  */