X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FRtsStartup.c;h=edbf88a9c63accf99826fb0c24a576568f8a8b5c;hb=29da2cf3011c292bc4261601aff85afb13e24d54;hp=0c5c2a36cb989815fc0ef2a26769d5eec9a0a1fb;hpb=cffcb52b7b7518db39d64394270392d06215cf90;p=ghc-hetmet.git diff --git a/ghc/rts/RtsStartup.c b/ghc/rts/RtsStartup.c index 0c5c2a3..edbf88a 100644 --- a/ghc/rts/RtsStartup.c +++ b/ghc/rts/RtsStartup.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * $Id: RtsStartup.c,v 1.75 2003/08/22 22:24:15 sof Exp $ + * $Id: RtsStartup.c,v 1.78 2003/09/26 12:12:35 panne Exp $ * * (c) The GHC Team, 1998-2002 * @@ -60,12 +60,39 @@ #include #endif +#ifdef HAVE_TERMIOS_H +#include +#endif +#ifdef HAVE_SIGNAL_H +#include +#endif + // Flag Structure struct RTS_FLAGS RtsFlags; // Count of how many outstanding hs_init()s there have been. static int hs_init_count = 0; +// Here we save the terminal settings on the standard file +// descriptors, if we need to change them (eg. to support NoBuffering +// input). +static void *saved_termios[3] = {NULL,NULL,NULL}; + +void* +__hscore_get_saved_termios(int fd) +{ + return (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) ? + saved_termios[fd] : NULL; +} + +void +__hscore_set_saved_termios(int fd, void* ts) +{ + if (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) { + saved_termios[fd] = ts; + } +} + /* ----------------------------------------------------------------------------- Starting up the RTS -------------------------------------------------------------------------- */ @@ -319,6 +346,27 @@ hs_exit(void) resetNonBlockingFd(1); resetNonBlockingFd(2); +#if HAVE_TERMIOS_H + // Reset the terminal settings on the standard file descriptors, + // if we changed them. See System.Posix.Internals.tcSetAttr for + // more details, including the reason we termporarily disable + // SIGTTOU here. + { + int fd; + sigset_t sigset, old_sigset; + sigemptyset(&sigset); + sigaddset(&sigset, SIGTTOU); + sigprocmask(SIG_BLOCK, &sigset, &old_sigset); + for (fd = 0; fd <= 2; fd++) { + struct termios* ts = (struct termios*)__hscore_get_saved_termios(fd); + if (ts != NULL) { + tcsetattr(fd,TCSANOW,ts); + } + } + sigprocmask(SIG_SETMASK, &old_sigset, NULL); + } +#endif + #if defined(PAR) /* controlled exit; good thread! */ shutdownParallelSystem(0);