=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/ext.c,v retrieving revision 1.1.1.1 retrieving revision 1.15 diff -u -p -r1.1.1.1 -r1.15 --- OpenXM/src/kan96xx/Kan/ext.c 1999/10/08 02:12:02 1.1.1.1 +++ OpenXM/src/kan96xx/Kan/ext.c 2003/07/21 13:36:41 1.15 @@ -1,3 +1,4 @@ +/* $OpenXM: OpenXM/src/kan96xx/Kan/ext.c,v 1.14 2003/07/14 12:49:52 takayama Exp $ */ #include #include #include @@ -11,7 +12,11 @@ #include "extern2.h" #include #include "plugin.h" +#include +#include "ox_pathfinder.h" +extern char **environ; + #define MYCP_SIZE 100 static int Mychildren[MYCP_SIZE]; static int Mycp = 0; @@ -25,7 +30,7 @@ static void mywait() { for (i=0; i 0) Mycp--; } @@ -34,9 +39,14 @@ static void mywait() { } #define SIZE_OF_ENVSTACK 5 -static jmp_buf EnvStack[SIZE_OF_ENVSTACK]; +#if defined(__CYGWIN__) +#define JMP_BUF sigjmp_buf +#else +#define JMP_BUF jmp_buf +#endif +static JMP_BUF EnvStack[SIZE_OF_ENVSTACK]; static int Envp = 0; -static void pushEnv(jmp_buf jb) { +static void pushEnv(JMP_BUF jb) { if (Envp < SIZE_OF_ENVSTACK) { *(EnvStack[Envp]) = *jb; Envp++; @@ -45,7 +55,7 @@ static void pushEnv(jmp_buf jb) { exit(2); } } -static void popEnv(jmp_buf jbp) { +static void popEnv(JMP_BUF jbp) { if (Envp <= 0) { fprintf(stderr,"Underflow of EnvStack.\n"); exit(3); @@ -80,12 +90,16 @@ 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, uid; int argListc, fdListc; char *abc; char *abc2; extern struct context *CurrentContextp; +#if (__CYGWIN__) + extern sigjmp_buf EnvOfStackMachine; +#else extern jmp_buf EnvOfStackMachine; +#endif extern void ctrlC(); extern int SigIgn; extern errno; @@ -94,7 +108,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 +146,211 @@ 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 defined(__CYGWIN__) + if (abc == NULL) { + abc2 = (char *)sGC_malloc(sizeof(char)*(strlen(KopString(obj1))+2)); + strcpy(abc2,KopString(obj1)); + for (i=0; i 0) { + /* parent */ + if (m&2) { + /* 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; i>>\n"); + } + execve(argv[0],argv,environ); + /* This place will never be reached unless execv fails. */ + fprintf(stderr,"forkExec fails: "); + for (i=0; ilc).ival,(obj2.rc.op->rc).ival, + m,CurrentContextp->userDictionary); + }else if (strcmp(key,"getServerEnv")==0) { + if (size != 2) errorKan1("%s\n","[(getServerEnv) serverName] extension."); + obj1 = getoa(obj,1); + if (obj1.tag != Sdollar) errorKan1("%s\n","[(getServerEnv) serverName] extension."); + { + char **se; int ii; int nn; + se = getServerEnv(KopString(obj1)); + if (se == NULL) { + debugServerEnv(KopString(obj1)); + rob = NullObject; + }else{ + for (ii=0,nn=0; se[ii] != NULL; ii++) nn++; + rob = newObjectArray(nn); + for (ii=0; ii