Subject: Re: bash hangs on sparc64
To: None <martti.kuparinen@iki.fi>
From: Shin'ichiro TAYA <taya@ba2.so-net.ne.jp>
List: port-sparc64
Date: 08/30/2001 18:20:07
From: Martti Kuparinen <martti.kuparinen@iki.fi>
Subject: bash hangs on sparc64
Date: Thu, 30 Aug 2001 11:14:20 +0300 (EEST)

> Hi!
> 
> I installed 1.5.1 on a Sun Ultra 5 and installed bash-2.05 from
> /usr/pkgsrc. Then I started bash and started to type a command.
> I made a typo so I pressed ^C before pressing Enter.
> 
> Result: bash hangs! Nothing works, no ^Z, no "kill pid" from another
> xterm. The only solution is to "kill -9 pid" from another xterm.
> Top shows that the bash process is running all the time:

Maybe those patches will help you.

-taya

diff -ru ../Orig/bash-2.05/unwind_prot.c ./unwind_prot.c
--- ../Orig/bash-2.05/unwind_prot.c	Thu Feb 15 07:00:55 2001
+++ ./unwind_prot.c	Sat Jul 14 14:07:17 2001
@@ -51,7 +51,7 @@
    points to this. */
 typedef struct {
   int *variable;
-  char *desired_setting;
+  UWP desired_setting;
   int size;
 } SAVED_VAR;
 
@@ -280,8 +280,9 @@
 discard_saved_var (sv)
      SAVED_VAR *sv;
 {
-  if (sv->size != sizeof (int))
-    free (sv->desired_setting);
+ if (sv->size != sizeof (int) && sv->size != sizeof (short) &&
+      sv->size != sizeof (char *))
+   free (sv->desired_setting.p);
   free (sv);
 }
 
@@ -293,13 +294,16 @@
 restore_variable (sv)
      SAVED_VAR *sv;
 {
-  if (sv->size != sizeof (int))
-    {
-      FASTCOPY ((char *)sv->desired_setting, (char *)sv->variable, sv->size);
-      free (sv->desired_setting);
-    }
-  else
-    *(sv->variable) = (int)sv->desired_setting;
+ if (sv->size == sizeof (int))
+   *(int *)(sv->variable) = sv->desired_setting.i;
+ else if (sv->size == sizeof (short))
+   *(short *)(sv->variable) = sv->desired_setting.s;
+ else if (sv->size == sizeof (char *))
+   *(char **)(sv->variable) = sv->desired_setting.p;
+ else { 
+     FASTCOPY ((char *)sv->desired_setting.p, (char *)sv->variable, sv->size);
+     free (sv->desired_setting.p);
+ }
 
   free (sv);
 }
@@ -312,19 +316,22 @@
 void
 unwind_protect_var (var, value, size)
      int *var;
-     char *value;
+     UWP *value;
      int size;
 {
   SAVED_VAR *s = (SAVED_VAR *)xmalloc (sizeof (SAVED_VAR));
 
   s->variable = var;
-  if (size != sizeof (int))
-    {
-      s->desired_setting = (char *)xmalloc (size);
-      FASTCOPY (value, (char *)s->desired_setting, size);
-    }
-  else
-    s->desired_setting = value;
+  if (size == sizeof (int)) {
+    s->desired_setting.i = value->i;
+  } else if (size == sizeof (short)) {
+    s->desired_setting.s = value->s;
+  } else if (size == sizeof (char *)) {
+    s->desired_setting.p = value->p;
+  } else {
+       s->desired_setting.p = (char *)xmalloc (size);
+       FASTCOPY (value, (char *)s->desired_setting.p, size);
+  }
   s->size = size;
   add_unwind_protect ((Function *)restore_variable, (char *)s);
 }
diff -ru ../Orig/bash-2.05/unwind_prot.h ./unwind_prot.h
--- ../Orig/bash-2.05/unwind_prot.h	Fri Feb  2 03:51:00 2001
+++ ./unwind_prot.h	Sat Jul 14 14:13:23 2001
@@ -34,8 +34,9 @@
 /* Try to force correct alignment on machines where pointers and ints
    differ in size. */
 typedef union {
-  char *s;
+  char *p;
   int i;
+  int s;
 } UWP;
 
 /* Define for people who like their code to look a certain way. */
@@ -47,18 +48,28 @@
 	  { \
 	    UWP u; \
 	    u.i = (X); \
-	    unwind_protect_var (&(X), u.s, sizeof (int)); \
+	    unwind_protect_var (&(X), &u, sizeof (int)); \
 	  } \
 	while (0)
 
 #define unwind_protect_short(X) \
-  unwind_protect_var ((int *)&(X), (char *)&(X), sizeof (short))
+	do \
+	  { \
+	    UWP u; \
+	    u.i = (X); \
+	    unwind_protect_var (&(X), &u, sizeof (int)); \
+	  } \
+	while (0)
 
 /* How to protect a pointer to a string. */
 #define unwind_protect_string(X) \
-  unwind_protect_var ((int *)&(X), \
-		      ((sizeof (char *) == sizeof (int)) ? (char *) (X) : (char *) &(X)), \
-		       sizeof (char *))
+	do \
+	{ \
+	  UWP u; \
+	  u.p = (X); \
+	  unwind_protect_var (&(X), &u, sizeof (char *)); \
+	} \
+	while (0)
 
 /* How to protect any old pointer. */
 #define unwind_protect_pointer(X) unwind_protect_string (X)