Re: stdin seekable failure

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

According to Eric Blake on 4/12/2007 10:11 AM:
>> So I suggest creating a new module 'closein' instead.
> 
> Done like so.
> 
> 2007-04-12  Eric Blake  <[email protected]>
> 
> 	Work around glibc's failure to reset seekable stdin on exit.
> 	* modules/closein: New module.

And used here.  Ralf, do you mind checking if this resolved the failure
you saw?

2007-04-12  Eric Blake  <[email protected]>

	Work around 'stdin seekable' shortcoming on glibc.
	* ltdl/m4/gnulib-cache.m4: Use closein instead of closeout.
	* tests/others.at (stdin closed): Adjust to new output.
	* src/main.c (process_file): No need to return anything.
	(main): Use close_stdin instead of close_stdout.
	Reported by Ralf Wildenhues.

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

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

iD8DBQFGHl0g84KuGfSFAYARAkNuAKCbZLAW6tr+EWrY5/whJqgPDcdMlgCdFQrC
t5ebGhHSP12DnvRdUlO3Lqw=
=7hq3
-----END PGP SIGNATURE-----

_______________________________________________
M4-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-patches
m4.patch258 (text/plain, 6.8 KB)
Index: ltdl/m4/gnulib-cache.m4
===================================================================
RCS file: /sources/m4/m4/ltdl/m4/gnulib-cache.m4,v
retrieving revision 1.26
diff -u -p -r1.26 gnulib-cache.m4
--- ltdl/m4/gnulib-cache.m4	12 Apr 2007 12:30:21 -0000	1.26
+++ ltdl/m4/gnulib-cache.m4	12 Apr 2007 16:20:38 -0000
@@ -15,11 +15,11 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libgnu --source-base=gnu --m4-base=ltdl/m4 --doc-base=doc --aux-dir=ltdl/config --libtool --macro-prefix=M4 assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closeout config-h configmake dirname error exit fdl fflush filenamecat fopen-safer fprintf-posix free gendocs gettext gnupload mkstemp obstack progname regex regexprops-generic sprintf-posix stdbool stdlib-safer strnlen strtol tempname unlocked-io vasprintf-posix verror xalloc xalloc-die xstrndup xstrtol xvasprintf
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=gnu --m4-base=ltdl/m4 --doc-base=doc --aux-dir=ltdl/config --libtool --macro-prefix=M4 assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closein config-h configmake dirname error exit fdl fflush filenamecat fopen-safer fprintf-posix free gendocs gettext gnupload mkstemp obstack progname regex regexprops-generic sprintf-posix stdbool stdlib-safer strnlen strtol tempname unlocked-io vasprintf-posix verror xalloc xalloc-die xstrndup xstrtol xvasprintf
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
-gl_MODULES([assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closeout config-h configmake dirname error exit fdl fflush filenamecat fopen-safer fprintf-posix free gendocs gettext gnupload mkstemp obstack progname regex regexprops-generic sprintf-posix stdbool stdlib-safer strnlen strtol tempname unlocked-io vasprintf-posix verror xalloc xalloc-die xstrndup xstrtol xvasprintf])
+gl_MODULES([assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closein config-h configmake dirname error exit fdl fflush filenamecat fopen-safer fprintf-posix free gendocs gettext gnupload mkstemp obstack progname regex regexprops-generic sprintf-posix stdbool stdlib-safer strnlen strtol tempname unlocked-io vasprintf-posix verror xalloc xalloc-die xstrndup xstrtol xvasprintf])
 gl_AVOID([])
 gl_SOURCE_BASE([gnu])
 gl_M4_BASE([ltdl/m4])
Index: src/main.c
===================================================================
RCS file: /sources/m4/m4/src/main.c,v
retrieving revision 1.111
diff -u -p -r1.111 main.c
--- src/main.c	2 Apr 2007 12:06:23 -0000	1.111
+++ src/main.c	12 Apr 2007 16:20:38 -0000
@@ -26,7 +26,7 @@
 #include "m4.h"
 
 #include "close-stream.h"
-#include "closeout.h"
+#include "closein.h"
 #include "configmake.h"
 #include "getopt.h"
 #include "version-etc.h"
@@ -298,15 +298,11 @@ size_opt (char const *opt, char const *m
 
 /* Process a command line file NAME, and return true only if it was
    stdin.  */
-static bool
+static void
 process_file (m4 *context, const char *name)
 {
-  bool result = false;
   if (strcmp (name, "-") == 0)
-    {
-      m4_push_file (context, stdin, "stdin", false);
-      result = true;
-    }
+    m4_push_file (context, stdin, "stdin", false);
   else
     {
       char *full_name;
@@ -314,13 +310,12 @@ process_file (m4 *context, const char *n
       if (fp == NULL)
 	{
 	  m4_error (context, 0, errno, _("cannot open file `%s'"), name);
-	  return false;
+	  return;
 	}
       m4_push_file (context, fp, full_name, true);
       free (full_name);
     }
   m4_macro_expand_input (context);
-  return result;
 }
 
 
@@ -334,7 +329,6 @@ main (int argc, char *const *argv, char 
   int optchar;			/* option character */
   size_t size;			/* for parsing numeric option arguments */
 
-  bool read_stdin = false;	/* true iff we have read from stdin */
   bool import_environment = false; /* true to import environment */
   bool seen_file = false;
   const char *debugfile = NULL;
@@ -348,7 +342,7 @@ main (int argc, char *const *argv, char 
 
   /* Initialize gnulib error module.  */
   m4_set_program_name (argv[0]);
-  atexit (close_stdout);
+  atexit (close_stdin);
 
   setlocale (LC_ALL, "");
 #ifdef ENABLE_NLS
@@ -702,7 +696,7 @@ main (int argc, char *const *argv, char 
 	  break;
 
 	case '\1':
-	  read_stdin |= process_file (context, arg);
+	  process_file (context, arg);
 	  break;
 
 	case POPDEF_OPTION:
@@ -743,10 +737,10 @@ main (int argc, char *const *argv, char 
      and the input read.  */
 
   if (optind == argc && !seen_file)
-    read_stdin = process_file (context, "-");
+    process_file (context, "-");
   else
     for (; optind < argc; optind++)
-      read_stdin |= process_file (context, argv[optind]);
+      process_file (context, argv[optind]);
 
   /* Now handle wrapup text.
      FIXME - when -F is in effect, should wrapped text be frozen?  */
@@ -772,11 +766,9 @@ main (int argc, char *const *argv, char 
   m4_input_exit ();
 
   /* Change debug stream back to stderr, to force flushing the debug
-     stream and detect any errors it might have encountered.  Close
-     stdin if we read from it, to detect any errors.  */
+     stream and detect any errors it might have encountered.  The
+     three standard streams are closed by close_stdin.  */
   m4_debug_set_output (context, NULL);
-  if (read_stdin && close_stream (stdin) == EOF)
-    m4_error (context, 0, errno, _("error closing stdin"));
 
   exit_status = m4_get_exit_status (context);
   m4_delete (context);
Index: tests/others.at
===================================================================
RCS file: /sources/m4/m4/tests/others.at,v
retrieving revision 1.32
diff -u -p -r1.32 others.at
--- tests/others.at	11 Apr 2007 15:48:09 -0000	1.32
+++ tests/others.at	12 Apr 2007 16:20:38 -0000
@@ -405,20 +405,20 @@ AT_CHECK_M4([in.m4], [0], [[hello world
 dnl error when stdin must be read
 AT_CHECK_M4([], [1], [],
 [[m4:stdin:1: error reading file `stdin'
-m4: error closing stdin: Bad file descriptor
+m4: error closing file: Bad file descriptor
 ]], [-])
 
 dnl error when stdin must be read
 AT_CHECK_M4([-], [1], [],
 [[m4:stdin:1: error reading file `stdin'
-m4: error closing stdin: Bad file descriptor
+m4: error closing file: Bad file descriptor
 ]], [-])
 
 dnl error once per command-line attempt to read stdin
 AT_CHECK_M4([- in.m4 -], [1], [[hello world
 ]], [[m4:stdin:1: error reading file `stdin'
 m4:stdin:1: error reading file `stdin'
-m4: error closing stdin: Bad file descriptor
+m4: error closing file: Bad file descriptor
 ]], [-])
 
 dnl command line and trace file must not collide with stdin
@@ -446,7 +446,7 @@ divert`'world
 ]])
 AT_CHECK_M4([in.m4 - in2.m4], [1], [[hello world
 ]], [[m4:stdin:1: error reading file `stdin'
-m4: error closing stdin: Bad file descriptor
+m4: error closing file: Bad file descriptor
 ]], [-])
 
 AT_CLEANUP
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.