=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/ext.c,v retrieving revision 1.1.1.1 retrieving revision 1.6 diff -u -p -r1.1.1.1 -r1.6 --- OpenXM/src/kan96xx/Kan/ext.c 1999/10/08 02:12:02 1.1.1.1 +++ OpenXM/src/kan96xx/Kan/ext.c 2001/08/09 22:13:58 1.6 @@ -1,3 +1,4 @@ +/* $OpenXM: OpenXM/src/kan96xx/Kan/ext.c,v 1.5 2001/05/04 01:06:23 takayama Exp $ */ #include #include #include @@ -25,7 +26,7 @@ static void mywait() { for (i=0; i 0) Mycp--; } @@ -80,7 +81,7 @@ struct object Kextension(struct object obj) struct object keyo; struct object rob = NullObject; struct object obj1,obj2,obj3,obj4; - int m,i; + int m,i,pid; int argListc, fdListc; char *abc; char *abc2; @@ -94,7 +95,8 @@ struct object Kextension(struct object obj) struct stat buf; char **argv; FILE *fp; - void (*oldsig)(); + void (*oldsig)(); + extern SecureMode; if (obj.tag != Sarray) errorKan1("%s\n","Kextension(): The argument must be an array."); size = getoaSize(obj); @@ -131,141 +133,147 @@ struct object Kextension(struct object obj) if (!( m == 0 || m == PROTECT || m == ABSOLUTE_PROTECT)) errorKan1("%s\n","The number must be 0, 1 or 2."); putUserDictionary2((char *)NULL,0,0,m | SET_ATTR_FOR_ALL_WORDS, - CurrentContextp->userDictionary); + CurrentContextp->userDictionary); }else if (strcmp(key,"keywords")==0) { if (size != 1) errorKan1("%s\n","[(keywords)] extension."); rob = showSystemDictionary(1); /* }else if (strcmp(key,"fork0")==0) { - if (size != 2) errorKan1("%s\n","[(fork0) sss] extension."); - m = fork(); - if (m>0) { rob = KpoInteger(m); } - else { - system(KopString(getoa(obj,1))); exit(0); - } */ - }else if (strcmp(key,"defaultPolyRing")==0) { - if (size != 2) errorKan1("%s\n","[(defaultPolyRing) n] extension."); - rob = KdefaultPolyRing(getoa(obj,1)); - }else if (strcmp(key,"getenv")==0) { - if (size != 2) errorKan1("%s\n","[(getenv) envstr] extension."); - obj1 = getoa(obj,1); - if (obj1.tag != Sdollar) errorKan1("%s\n","[(getenv) envstr] extension"); - abc = getenv(KopString(obj1)); - if (abc == NULL) { - rob = NullObject; + if (size != 2) errorKan1("%s\n","[(fork0) sss] extension."); + m = fork(); + if (m>0) { rob = KpoInteger(m); } + else { + system(KopString(getoa(obj,1))); exit(0); + } */ + }else if (strcmp(key,"defaultPolyRing")==0) { + if (size != 2) errorKan1("%s\n","[(defaultPolyRing) n] extension."); + rob = KdefaultPolyRing(getoa(obj,1)); + }else if (strcmp(key,"getenv")==0) { + if (size != 2) errorKan1("%s\n","[(getenv) envstr] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sdollar) errorKan1("%s\n","[(getenv) envstr] extension"); + abc = getenv(KopString(obj1)); + if (abc == NULL) { + rob = NullObject; + }else{ + abc2 = (char *)sGC_malloc(sizeof(char)*(strlen(abc)+2)); + strcpy(abc2,abc); + rob = KpoString(abc2); + } + }else if (strcmp(key,"stat")==0) { + if (size != 2) errorKan1("%s\n","[(stat) fname] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sdollar) errorKan1("%s\n","[(stat) fname] extension ; string fname."); + m = stat(KopString(obj1),&buf); + rob = newObjectArray(2); + if (m == -1) { + /* fail */ + obj2 = NullObject; + putoa(rob,0,obj2); + obj3 = newObjectArray(2); + putoa(obj3,0,KpoString("error no")); + putoa(obj3,1,KpoInteger(errno)); + putoa(rob,1,obj3); + }else{ + /* success */ + putoa(rob,0,KpoInteger(0)); + obj3 = newObjectArray(1); + putoa(obj3,0,KpoInteger((int) buf.st_size)); + putoa(rob,1,obj3); /* We have not yet read buf fully */ + } + }else if (strcmp(key,"forkExec")==0) { + if (size != 4) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sarray) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension. array argList."); + obj2 = getoa(obj,2); + if (obj2.tag != Sarray) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension. array fdList."); + obj3 = getoa(obj,3); + if (obj3.tag != Sinteger) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension. integer sigblock."); + m = KopInteger(obj3); /* m == 1 : block ctrl-C. */ + argListc = getoaSize(obj1); + fdListc = getoaSize(obj2); + if ((pid = fork()) > 0) { + /* parent */ + if (m&3) { + /* Do not call singal to turn around a trouble on cygwin. BUG. */ }else{ - abc2 = (char *)sGC_malloc(sizeof(char)*(strlen(abc)+2)); - strcpy(abc2,abc); - rob = KpoString(abc2); + signal(SIGCHLD,mywait); /* to kill Zombie */ } - }else if (strcmp(key,"stat")==0) { - if (size != 2) errorKan1("%s\n","[(stat) fname] extension."); - obj1 = getoa(obj,1); - if (obj1.tag != Sdollar) errorKan1("%s\n","[(stat) fname] extension ; string fname."); - m = stat(KopString(obj1),&buf); - rob = newObjectArray(2); - if (m == -1) { - /* fail */ - obj2 = NullObject; - putoa(rob,0,obj2); - obj3 = newObjectArray(2); - putoa(obj3,0,KpoString("error no")); - putoa(obj3,1,KpoInteger(errno)); - putoa(rob,1,obj3); - }else{ - /* success */ - putoa(rob,0,KpoInteger(0)); - putoa(rob,1,newObjectArray(0)); /* We have not yet read buf */ + Mychildren[Mycp++] = pid; + if (Mycp >= MYCP_SIZE-1) { + errorKan1("%s\n","Child process table is full.\n"); + Mycp = 0; } - }else if (strcmp(key,"forkExec")==0) { - if (size != 4) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension."); - obj1 = getoa(obj,1); - if (obj1.tag != Sarray) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension. array argList."); - obj2 = getoa(obj,2); - if (obj2.tag != Sarray) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension. array fdList."); - obj3 = getoa(obj,3); - if (obj3.tag != Sinteger) errorKan1("%s\n","[(forkExec) argList fdList sigblock] extension. integer sigblock."); - m = KopInteger(obj3); /* m == 1 : block ctrl-C. */ - argListc = getoaSize(obj1); - fdListc = getoaSize(obj2); - if ((m = fork()) > 0) { - /* parent */ - signal(SIGCHLD,mywait); /* to kill Zombie */ - Mychildren[Mycp++] = m; - if (Mycp >= MYCP_SIZE-1) { - errorKan1("%s\n","Child process table is full.\n"); - Mycp = 0; - } - rob = KpoInteger(m); - /* Done */ - }else{ - /* Child */ - for (i=0; ilc).ival,(obj2.rc.op->rc).ival, - m,CurrentContextp->userDictionary); + argv = (char **) sGC_malloc(sizeof(char *)*(argListc+1)); + if (argv == NULL) { + fprintf(stderr," no more momory. forkExec --- exiting.\n"); + _exit(10); + } + for (i=0; ilc).ival,(obj2.rc.op->rc).ival, + m,CurrentContextp->userDictionary); + } #include "plugin.hh" else{ errorKan1("%s\n","Unknown tag for extension.");