| Bill Allombert on Wed, 07 Dec 2005 00:40:34 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: hangling interrupt |
On Mon, Dec 05, 2005 at 04:40:09PM -0500, Igor Schein wrote:
> Hi,
>
> Don't try this in a gp session you care about:
>
> k=0;while(k++,print(k);system("sleep 1"))
>
> Now that's what I call a true infinite loop, the one you cannot break
> out of. Even ^\ doesn't work, only ^Z and good-bye session. I have a
> feeling it's non-trivial to handle this scenario properly.
The attached path should fix that provided a suitable
has_waitpid.c file is provided, and /bin/sh is a shell.
I am not sure it is worth the hassle though...
Cheers,
Bill.
Index: src/gp/gp.c
===================================================================
RCS file: /home/cvs/pari/src/gp/gp.c,v
retrieving revision 1.279
diff -u -r1.279 gp.c
--- src/gp/gp.c 22 Nov 2005 09:23:06 -0000 1.279
+++ src/gp/gp.c 6 Dec 2005 23:37:53 -0000
@@ -24,6 +24,12 @@
#include "gp.h"
#include "../graph/rect.h"
+#define HAS_WAITPID
+#ifdef HAS_WAITPID
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/wait.h>
+#endif
#ifdef _WIN32
# include <windows.h>
# ifndef WINCE
@@ -1698,7 +1704,16 @@
void
system0(char *s)
{
-#if defined(UNIX) || defined(__EMX__) || defined(_WIN32)
+#ifdef HAS_WAITPID
+ pid_t pid;
+ int status;
+ check_secure(s);
+ if (!(pid=fork()))
+ execl("/bin/sh","sh","-c",s,NULL);
+ waitpid(pid,&status,0);
+ if (WIFSIGNALED(status) && WTERMSIG(status)>0)
+ sigint_fun();
+#elif defined(UNIX) || defined(__EMX__) || defined(_WIN32)
check_secure(s); system(s);
#else
err(archer);