Re: Frozen state generation fails with returncode 0

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

[adding m4-patches]

According to Jean-Charles Longuet on 5/21/2008 2:10 PM:
|
| When m4 fails to open() the frozen state file, it complains
| but the process exit code is still 0. However, the same function
| may trigger failures leading to a non-zero process exit code,
| for example when the close() of the frozen state file fails.

Thanks for the report.  Which version of m4 was this against?  I'm
guessing this was against a release tarball, rather than the current git
repository, since this area of code has changed in the meantime?

|
| Wouldn't it be consistent to also exit on open() failures,
| with this one-line patch or equivalent ?

abort() is too strong - users should not get a core dump merely because
they requested a file that can't be opened.  So I'll be applying this instead:

- --
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

iEYEARECAAYFAkg07bkACgkQ84KuGfSFAYDg3ACgkAWSHOmo/6ZEJN0UfFFjvpQO
rEsAoNS6qOHX6jvJYYsKNaBRToRPVhmB
=UMHy
-----END PGP SIGNATURE-----

_______________________________________________
M4-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-patches
m4.patch351 (text/plain, 2 KB)
From ebc0275ff983bf9016ffb4f19eb5a4c678691b54 Mon Sep 17 00:00:00 2001
From: Eric Blake <[email protected]>
Date: Wed, 21 May 2008 21:49:54 -0600
Subject: [PATCH] Don't allow failure to freeze give exit status of 0.

* src/freeze.c (produce_frozen_state): Die rather than warn.
* doc/m4.texinfo (Using frozen files): Test it.
* THANKS: Update.
Reported by Jean-Charles Longuet.

Signed-off-by: Eric Blake <[email protected]>
---
 ChangeLog      |    8 ++++++++
 THANKS         |    1 +
 doc/m4.texinfo |   10 ++++++++++
 src/freeze.c   |    5 +----
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2abc489..9307dda 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-05-22  Eric Blake  <[email protected]>
+
+	Don't allow failure to freeze give exit status of 0.
+	* src/freeze.c (produce_frozen_state): Die rather than warn.
+	* doc/m4.texinfo (Using frozen files): Test it.
+	* THANKS: Update.
+	Reported by Jean-Charles Longuet.
+
 2008-05-09  Eric Blake  <[email protected]>
 
 	Improve error message when frozen file is invalid.
diff --git a/THANKS b/THANKS
index 19c1d92..1fa9ba5 100644
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index 3131e9a..380bc34 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -6993,6 +6993,16 @@ ifdef(`__unix__', ,
 ')m4exit(`77')')dnl
 traceon(`undefined')dnl
 @end example
+
+@c Make sure freezing is successful.
+
+@comment options -F /none/such
+@comment status: 1
+@example
+$ @kbd{m4 -F /none/such}
+^D
+@error{}m4: cannot open /none/such: No such file or directory
+@end example
 @end ignore
 
 When an @code{m4} run is to be frozen, the automatic undiversion
diff --git a/src/freeze.c b/src/freeze.c
index 15f06fe..2734efa 100644
--- a/src/freeze.c
+++ b/src/freeze.c
@@ -58,10 +58,7 @@ produce_frozen_state (const char *name)
 
   file = fopen (name, O_BINARY ? "wb" : "w");
   if (!file)
-    {
-      m4_error (0, errno, NULL, _("cannot open %s"), name);
-      return;
-    }
+    m4_error (EXIT_FAILURE, errno, NULL, _("cannot open %s"), name);
 
   /* Write a recognizable header.  */
 
-- 
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.