Changes to make sure that Scheme does not get into an infinite loop on
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Wed, 24 Jul 1991 19:48:29 +0000 (19:48 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Wed, 24 Jul 1991 19:48:29 +0000 (19:48 +0000)
input when a trap occurs or its tty disappears.

v7/src/microcode/uxsig.c
v7/src/microcode/uxtrap.c
v7/src/microcode/uxtrap.h
v7/src/microcode/uxutil.c
v7/src/microcode/version.h
v8/src/microcode/version.h

index 223baebd111fa0d86d92f27c5352248ee14bee82..fd62d1a64f83e9787c16981edcd8d557f00d2777 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxsig.c,v 1.12 1991/07/05 23:31:35 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxsig.c,v 1.13 1991/07/24 19:48:20 jinx Exp $
 
 Copyright (c) 1990-91 Massachusetts Institute of Technology
 
@@ -768,6 +768,13 @@ DEFUN (interactive_interrupt_handler, (scp), struct FULL_SIGCONTEXT * scp)
              fflush (stdout);
            }
          return;
+       case '\0':              /* C-@ */
+         if (errno != 0)
+         {
+           /* IO problems, assume everything scrod. */
+           fprintf (stderr, "Problems reading keyboard input -- Exitting.\n");
+           termination_eof ();
+         }
        default:
          if (!option_emacs_subprocess)
            print_interactive_help ();
@@ -978,6 +985,10 @@ DEFUN (reset_query, (scp), struct FULL_SIGCONTEXT * scp)
               "Action -> ",
               reset_choices))
        {
+       case '\0':
+         /* IO problems, assume everything scrod. */
+         fprintf (stderr, "Problems reading keyboard input -- exitting.\n");
+         termination_eof ();
        case 'D':
          SET_CRITICAL_SECTION_HOOK (soft_reset);
          return;
@@ -1009,6 +1020,12 @@ DEFUN_VOID (examine_memory)
       while (scan < end)
        {
          char c = (userio_read_char ());
+         if ((c == '\0') && (errno != 0))
+         {
+           /* IO problems, assume everything scrod. */
+           fprintf (stderr, "Problems reading keyboard input -- exiting.\n");
+           termination_eof ();
+         }
          (*scan) = c;
          if (c == '\n')
            c = '\0';
index 739d0a042cdc8bb15caab9266b5cd66d0fc2d61e..0308fc7caab9d79d0f36b2e08b9c9baae89d1cf4 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtrap.c,v 1.13 1991/07/12 23:17:37 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtrap.c,v 1.14 1991/07/24 19:48:24 jinx Exp $
 
 Copyright (c) 1990-91 Massachusetts Institute of Technology
 
@@ -72,9 +72,17 @@ DEFUN (OS_set_trap_state, (state), enum trap_state state)
   return (old_trap_state);
 }
 
+static void
+DEFUN_VOID (trap_normal_termination)
+{
+  trap_state = trap_state_exitting_soft;
+  termination_trap ();
+}
+
 static void
 DEFUN_VOID (trap_immediate_termination)
 {
+  trap_state = trap_state_exitting_hard;
   OS_restore_external_state ();
   exit (1);
 }
@@ -114,21 +122,30 @@ DEFUN (trap_handler, (message, signo, info, scp),
   int code = ((SIGINFO_VALID_P (info)) ? (SIGINFO_CODE (info)) : 0);
   Boolean constant_space_broken = (!(CONSTANT_SPACE_SEALED ()));
   enum trap_state old_trap_state = trap_state;
+
+  if (old_trap_state == trap_state_exitting_hard)
+  {
+    _exit (1);
+  }
+  else if (old_trap_state == trap_state_exitting_soft)
+  {
+    trap_immediate_termination ();
+  }
   trap_state = trap_state_trapped;
   if (WITHIN_CRITICAL_SECTION_P ())
-    {
-      fprintf (stdout,
-              "\n>> A %s has occurred within critical section \"%s\".\n",
-              message, (CRITICAL_SECTION_NAME ()));
-      fprintf (stdout, ">> [signal %d (%s), code %d]\n",
-              signo, (find_signal_name (signo)), code);
-    }
+  {
+    fprintf (stdout,
+            "\n>> A %s has occurred within critical section \"%s\".\n",
+            message, (CRITICAL_SECTION_NAME ()));
+    fprintf (stdout, ">> [signal %d (%s), code %d]\n",
+            signo, (find_signal_name (signo)), code);
+  }
   else if (constant_space_broken || (old_trap_state != trap_state_recover))
-    {
-      fprintf (stdout, "\n>> A %s has occurred.\n", message);
-      fprintf (stdout, ">> [signal %d (%s), code %d]\n",
-             signo, (find_signal_name (signo)), code);
-    }
+  {
+    fprintf (stdout, "\n>> A %s has occurred.\n", message);
+    fprintf (stdout, ">> [signal %d (%s), code %d]\n",
+            signo, (find_signal_name (signo)), code);
+  }
   if (constant_space_broken)
   {
     fputs (">> Constant space has been overwritten.\n", stdout);
@@ -136,78 +153,83 @@ DEFUN (trap_handler, (message, signo, info, scp),
           stdout);
   }
   fflush (stdout);
+
   switch (old_trap_state)
+  {
+  case trap_state_trapped:
+    if ((saved_trap_state == trap_state_recover) ||
+       (saved_trap_state == trap_state_query))
     {
-    case trap_state_trapped:
-      if ((saved_trap_state == trap_state_recover) ||
-         (saved_trap_state == trap_state_query))
-       {
-         fputs (">> The trap occurred while processing an earlier trap.\n",
-                stdout);
-         fprintf (stdout,
-                  ">> [The earlier trap raised signal %d (%s), code %d.]\n",
-                  saved_signo,
-                  (find_signal_name (saved_signo)),
-                  ((SIGINFO_VALID_P (saved_info))
-                   ? (SIGINFO_CODE (saved_info))
-                   : 0));
-         fputs (((WITHIN_CRITICAL_SECTION_P ())
-                 ? ">> Successful recovery is extremely unlikely.\n"
-                 : ">> Successful recovery is unlikely.\n"),
-                stdout);
-         break;
-       }
-      else
-       trap_immediate_termination ();
-    case trap_state_recover:
-      if ((WITHIN_CRITICAL_SECTION_P ()) || constant_space_broken)
-      {
-       fputs (">> Successful recovery is unlikely.\n", stdout);
-       break;
-      }
-      else
-      {
-       saved_trap_state = old_trap_state;
-       saved_signo = signo;
-       saved_info = info;
-       saved_scp = scp;
-       trap_recover ();
-      }
-    case trap_state_exit:
-      termination_trap ();
+      fputs (">> The trap occurred while processing an earlier trap.\n",
+            stdout);
+      fprintf (stdout,
+              ">> [The earlier trap raised signal %d (%s), code %d.]\n",
+              saved_signo,
+              (find_signal_name (saved_signo)),
+              ((SIGINFO_VALID_P (saved_info))
+               ? (SIGINFO_CODE (saved_info))
+               : 0));
+      fputs (((WITHIN_CRITICAL_SECTION_P ())
+             ? ">> Successful recovery is extremely unlikely.\n"
+             : ">> Successful recovery is unlikely.\n"),
+            stdout);
+      break;
+    }
+    else
+      trap_immediate_termination ();
+  case trap_state_recover:
+    if ((WITHIN_CRITICAL_SECTION_P ()) || constant_space_broken)
+    {
+      fputs (">> Successful recovery is unlikely.\n", stdout);
+      break;
     }
+    else
+    {
+      saved_trap_state = old_trap_state;
+      saved_signo = signo;
+      saved_info = info;
+      saved_scp = scp;
+      trap_recover ();
+    }
+  case trap_state_exit:
+    termination_trap ();
+  }
+
   fflush (stdout);
   saved_trap_state = old_trap_state;
   saved_signo = signo;
   saved_info = info;
   saved_scp = scp;
+    
   while (1)
+  {
+    static CONST char * trap_query_choices[] =
     {
-      static CONST char * trap_query_choices[] =
-       {
-         "D = dump core",
-         "I = terminate immediately",
-         "N = terminate normally",
-         "R = attempt recovery",
-         "Q = terminate normally",
-         0
-         };
-      switch (userio_choose_option
-             ("Choose one of the following actions:",
-              "Action -> ",
-              trap_query_choices))
-       {
-       case 'I':
-         trap_immediate_termination ();
-       case 'D':
-         trap_dump_core ();
-       case 'N':
-       case 'Q':
-         termination_trap ();
-       case 'R':
-         trap_recover ();
-       }
+      "D = dump core",
+      "I = terminate immediately",
+      "N = terminate normally",
+      "R = attempt recovery",
+      "Q = terminate normally",
+      0
+      };
+    switch (userio_choose_option
+           ("Choose one of the following actions:",
+            "Action -> ",
+            trap_query_choices))
+    {
+    case 'I':
+      trap_immediate_termination ();
+    case 'D':
+      trap_dump_core ();
+    case '\0':
+      /* Error in IO. Assume everything scrod. */
+    case 'N':
+    case 'Q':
+      trap_normal_termination ();
+    case 'R':
+      trap_recover ();
     }
+  }
 }
 \f
 #define STATE_UNKNOWN          (LONG_TO_UNSIGNED_FIXNUM (0))
index fa4fde069d0fc3e35901491d6b00e6c03271dfb8..3ea9aba39ab4d50ba90b1fa636ca35af0bdb2076 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtrap.h,v 1.10 1991/07/12 23:17:57 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxtrap.h,v 1.11 1991/07/24 19:48:26 jinx Exp $
 
 Copyright (c) 1990-91 Massachusetts Institute of Technology
 
@@ -410,7 +410,9 @@ enum trap_state
   trap_state_exit,
   trap_state_suspend,
   trap_state_query,
-  trap_state_recover
+  trap_state_recover,
+  trap_state_exitting_soft,
+  trap_state_exitting_hard
 };
 
 extern void EXFUN (initialize_trap_recovery, (char * C_sp));
index 64bd3c92f2220b94962fd97b42fdf6e375f1c506..3a850478020dfe464deaca9d859bcb193713f85c 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxutil.c,v 1.2 1991/01/07 23:57:29 cph Rel $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/uxutil.c,v 1.3 1991/07/24 19:48:29 jinx Exp $
 
 Copyright (c) 1990, 1991 Massachusetts Institute of Technology
 
@@ -132,10 +132,13 @@ DEFUN_VOID (userio_read_char)
   char c;
   while (1)
     {
-      int nread = (UX_read (STDIN_FILENO, (&c), 1));
+      int nread;
+
+      errno = 0;
+      nread = (UX_read (STDIN_FILENO, (&c), 1));
       if (nread == 1)
        break;
-      if ((nread < 0) && (errno != EINTR))
+      if (errno != EINTR)
        {
          c = '\0';
          break;
@@ -187,6 +190,8 @@ DEFUN (userio_choose_option, (herald, prompt, choices),
       fflush (stdout);
       {
        char command = (userio_read_char_raw ());
+       if ((command == '\0') && (errno != 0))
+         return (command);
        putc ('\n', stdout);
        fflush (stdout);
        if (islower (command))
@@ -225,6 +230,13 @@ DEFUN (userio_confirm, (prompt), CONST char * prompt)
        case 'n':
        case 'N':
          return (0);
+       case '\0':
+         if (errno != 0)
+         {
+           /* IO problems, assume everything scrod. */
+           fprintf (stderr, "Problems reading keyboard input -- exiting.\n");
+           termination_eof ();
+         }
        }
     }
 }
index a9bd7b8b0f69b9c155cf150c0bcba4bf6dbeddd1..8a7f23f06b26c4a155d0d1e760483fbdec50898c 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.90 1991/07/24 19:43:22 arthur Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 11.91 1991/07/24 19:47:41 jinx Exp $
 
 Copyright (c) 1988-91 Massachusetts Institute of Technology
 
@@ -46,5 +46,5 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     90
+#define SUBVERSION     91
 #endif
index 5bb7a0732b9ed9eed602f13323cbfbc8c8113466..46d8c37b5b07839633d30a1d6a3a3818b6fb7e31 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.90 1991/07/24 19:43:22 arthur Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 11.91 1991/07/24 19:47:41 jinx Exp $
 
 Copyright (c) 1988-91 Massachusetts Institute of Technology
 
@@ -46,5 +46,5 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     90
+#define SUBVERSION     91
 #endif