[project @ 1999-11-09 10:46:25 by simonmar]
authorsimonmar <unknown>
Tue, 9 Nov 1999 10:46:27 +0000 (10:46 +0000)
committersimonmar <unknown>
Tue, 9 Nov 1999 10:46:27 +0000 (10:46 +0000)
Reset standard file descriptors to blocking mode on exit.

ghc/lib/std/cbits/Makefile
ghc/lib/std/cbits/writeError.c
ghc/rts/RtsStartup.c
ghc/rts/RtsUtils.c
ghc/rts/RtsUtils.h

index f78d30a..4c95772 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.7 1999/10/29 13:52:30 sof Exp $
+# $Id: Makefile,v 1.8 1999/11/09 10:46:27 simonmar Exp $
 
 TOP = ../../..
 include $(TOP)/mk/boilerplate.mk
@@ -16,7 +16,7 @@ C_SRCS= $(wildcard *.c)
 
 C_OBJS  = $(C_SRCS:.c=.$(way_)o)
 LIBOBJS = $(C_OBJS)
-SRC_CC_OPTS += -O -I$(GHC_INCLUDE_DIR) $(GhcLibCcOpts)
+SRC_CC_OPTS += -O -I$(GHC_INCLUDE_DIR) -I$(GHC_RUNTIME_DIR) $(GhcLibCcOpts)
 
 ifneq "$(way)" "dll"
 SRC_CC_OPTS += -static
index 3f58833..59aa2b2 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1998
  *
- * $Id: writeError.c,v 1.3 1999/11/05 15:22:59 simonmar Exp $
+ * $Id: writeError.c,v 1.4 1999/11/09 10:46:27 simonmar Exp $
  *
  * hPutStr Runtime Support
  */
@@ -17,6 +17,7 @@ implementation in one or two places.)
 */
 
 #include "Rts.h"
+#include "RtsUtils.h"
 #include "stgio.h"
 
 #ifdef HAVE_FCNTL_H
@@ -32,13 +33,8 @@ StgInt len;
   int count = 0;
   char* p  = (char*)msg;
   char  nl = '\n';
-  long fd_flags;
 
-#if !defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__)
-    /* clear the non-blocking flag on this file descriptor */
-    fd_flags = fcntl(2, F_GETFL);
-    fcntl(2, F_SETFL, fd_flags & ~O_NONBLOCK);
-#endif
+  resetNonBlockingFd(2);
 
   /* Print error msg header */
   if (msg_hdr) {
index 8673986..bb387bf 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: RtsStartup.c,v 1.23 1999/11/02 17:19:15 simonmar Exp $
+ * $Id: RtsStartup.c,v 1.24 1999/11/09 10:46:26 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -192,6 +192,11 @@ shutdownHaskell(void)
   /* stop the ticker */
   initialize_virtual_timer(0);
   
+  /* reset the standard file descriptors to blocking mode */
+  resetNonBlockingFd(0);
+  resetNonBlockingFd(1);
+  resetNonBlockingFd(2);
+
   /* stop timing the shutdown, we're about to print stats */
   stat_endExit();
 
index d3d01cf..7b2ef75 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: RtsUtils.c,v 1.9 1999/08/25 16:11:51 simonmar Exp $
+ * $Id: RtsUtils.c,v 1.10 1999/11/09 10:46:26 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
 #include <time.h>
 #endif
 
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
 #include <stdarg.h>
 
 /* variable-argument error function. */
@@ -184,6 +188,26 @@ time_str(void)
 #endif
 
 /* -----------------------------------------------------------------------------
+ * Reset a file handle to blocking mode.  We do this for the standard
+ * file descriptors before exiting, because the shell doesn't always
+ * clean up for us.
+ * -------------------------------------------------------------------------- */
+
+void
+resetNonBlockingFd(int fd)
+{
+  long fd_flags;
+
+#if !defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__)
+  /* clear the non-blocking flag on this file descriptor */
+  fd_flags = fcntl(fd, F_GETFL);
+  if (fd_flags & O_NONBLOCK) {
+    fcntl(fd, F_SETFL, fd_flags & ~O_NONBLOCK);
+  }
+#endif
+}
+
+/* -----------------------------------------------------------------------------
    Print large numbers, with punctuation.
    -------------------------------------------------------------------------- */
 
index 8f4b2f6..8f871b0 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: RtsUtils.h,v 1.4 1999/03/17 13:19:23 simonm Exp $
+ * $Id: RtsUtils.h,v 1.5 1999/11/09 10:46:25 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -22,6 +22,8 @@ extern void raiseError( StgStablePtr handler );
 extern void stackOverflow(void);
 extern void heapOverflow(void);
 
+void resetNonBlockingFd(int fd);
+
 extern nat stg_strlen(char *str);
 
 /*Defined in Main.c, but made visible here*/