Re: Frozen state generation fails with returncode 0

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 5/22/2008 4:35 PM:
|> I had a look in the git repository, and the open() case seem to handle
|> errors. However, there are no checks on flose() return value in
|> produce_frozen_state(). Not sure if you already worked on it.
|
| You're right - a patch I hadn't ported to the master branch yet (this is
the
| patch on branch-1.4/branch-1.6:
| http://git.savannah.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=34c30#patch8).

Fixed as follows (and tested, on platforms with /dev/full).

- --
Don't work too hard, make some time for fun as well!

Eric Blake             [email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg2twwACgkQ84KuGfSFAYCAnACgwYu7ty3i4f/teZKtnlIjeTpE
/14AnR71gNxK1MuEr8c+h2vsZQPUKefN
=Cc96
-----END PGP SIGNATURE-----

_______________________________________________
M4-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-patches
m4.patch352 (text/plain, 2.8 KB)
From 3b8a1ff9f928e86d719169a81c7435a292eb25dd Mon Sep 17 00:00:00 2001
From: Eric Blake <[email protected]>
Date: Fri, 23 May 2008 06:20:40 -0600
Subject: [PATCH] Improve handling of frozen file errors.

* src/freeze.c (produce_frozen_state): Detect write failures.
(reload_frozen_state): Use close_stream.
* tests/freeze.at (freezing failure): New test.
* THANKS: Update.
Reported by Jean-Charles Longuet.

Signed-off-by: Eric Blake <[email protected]>
---
 ChangeLog       |    9 +++++++++
 THANKS          |    1 +
 src/freeze.c    |    7 +++++--
 tests/freeze.at |   19 +++++++++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c6c2b70..b05f806 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-05-23  Eric Blake  <[email protected]>
+
+	Improve handling of frozen file errors.
+	* src/freeze.c (produce_frozen_state): Detect write failures.
+	(reload_frozen_state): Use close_stream.
+	* tests/freeze.at (freezing failure): New test.
+	* THANKS: Update.
+	Reported by Jean-Charles Longuet.
+
 2008-05-21  Eric Blake  <[email protected]>
 
 	Stage 24a: Use full call context in error reporting.
diff --git a/THANKS b/THANKS
index 807bd1b..f6a22d6 100644
diff --git a/src/freeze.c b/src/freeze.c
index d32fc9e..40de809 100644
--- a/src/freeze.c
+++ b/src/freeze.c
@@ -25,6 +25,7 @@
 #include "m4.h"
 
 #include "binary-io.h"
+#include "close-stream.h"
 #include "quotearg.h"
 
 static	void  produce_mem_dump		(FILE *, const char *, size_t);
@@ -326,7 +327,9 @@ produce_frozen_state (m4 *context, const char *name)
   /* All done.  */
 
   fputs ("# End of frozen state file\n", file);
-  fclose (file);
+  if (close_stream (file) != 0)
+    m4_error (context, EXIT_FAILURE, errno, NULL,
+	      _("unable to create frozen state"));
 }
 
 /* Issue a message saying that some character is an EXPECTED character. */
@@ -941,7 +944,7 @@ ill-formed frozen file, version 2 directive `%c' encountered"), 'T');
   free (string[0]);
   free (string[1]);
   free (string[2]);
-  if (ferror (file) || fclose (file) != 0)
+  if (close_stream (file) != 0)
     m4_error (context, EXIT_FAILURE, errno, NULL,
 	      _("unable to read frozen state"));
   m4_set_current_file (context, NULL);
diff --git a/tests/freeze.at b/tests/freeze.at
index fbc446f..cffa926 100644
--- a/tests/freeze.at
+++ b/tests/freeze.at
@@ -51,6 +51,25 @@ AT_CLEANUP
 
 AT_BANNER([Freezing state.])
 
+## ---------------- ##
+## freezing failure ##
+## ---------------- ##
+
+AT_SETUP([freezing failure])
+AT_KEYWORDS([frozen])
+
+AT_CHECK_M4([-F /none/such], [1], [],
+[[m4: cannot open `/none/such': No such file or directory
+]])
+
+if test -w /dev/full && test -c /dev/full ; then
+  AT_CHECK_M4([-F /dev/full], [1], [],
+[[m4: unable to create frozen state: No space left on device
+]])
+fi
+AT_CLEANUP
+
+
 ## --------------- ##
 ## large diversion ##
 ## --------------- ##
-- 
1.5.5.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.