From ee6369a6d3bf8eef515285c9f9523e388c5c267e Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 9 Nov 1999 10:46:27 +0000 Subject: [PATCH] [project @ 1999-11-09 10:46:25 by simonmar] Reset standard file descriptors to blocking mode on exit. --- ghc/lib/std/cbits/Makefile | 4 ++-- ghc/lib/std/cbits/writeError.c | 10 +++------- ghc/rts/RtsStartup.c | 7 ++++++- ghc/rts/RtsUtils.c | 26 +++++++++++++++++++++++++- ghc/rts/RtsUtils.h | 4 +++- 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/ghc/lib/std/cbits/Makefile b/ghc/lib/std/cbits/Makefile index f78d30a..4c95772 100644 --- a/ghc/lib/std/cbits/Makefile +++ b/ghc/lib/std/cbits/Makefile @@ -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 diff --git a/ghc/lib/std/cbits/writeError.c b/ghc/lib/std/cbits/writeError.c index 3f58833..59aa2b2 100644 --- a/ghc/lib/std/cbits/writeError.c +++ b/ghc/lib/std/cbits/writeError.c @@ -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) { diff --git a/ghc/rts/RtsStartup.c b/ghc/rts/RtsStartup.c index 8673986..bb387bf 100644 --- a/ghc/rts/RtsStartup.c +++ b/ghc/rts/RtsStartup.c @@ -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(); diff --git a/ghc/rts/RtsUtils.c b/ghc/rts/RtsUtils.c index d3d01cf..7b2ef75 100644 --- a/ghc/rts/RtsUtils.c +++ b/ghc/rts/RtsUtils.c @@ -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 * @@ -19,6 +19,10 @@ #include #endif +#ifdef HAVE_FCNTL_H +#include +#endif + #include /* 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. -------------------------------------------------------------------------- */ diff --git a/ghc/rts/RtsUtils.h b/ghc/rts/RtsUtils.h index 8f4b2f6..8f871b0 100644 --- a/ghc/rts/RtsUtils.h +++ b/ghc/rts/RtsUtils.h @@ -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*/ -- 1.7.10.4