=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/shell.c,v retrieving revision 1.8 retrieving revision 1.11 diff -u -p -r1.8 -r1.11 --- OpenXM/src/kan96xx/Kan/shell.c 2003/12/05 07:05:24 1.8 +++ OpenXM/src/kan96xx/Kan/shell.c 2004/02/23 09:03:42 1.11 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/Kan/shell.c,v 1.7 2003/12/04 06:29:21 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/Kan/shell.c,v 1.10 2004/02/05 10:35:04 takayama Exp $ */ #include #include #include @@ -173,6 +173,28 @@ struct object KoxWhich(struct object cmdo,struct objec return(rob); } +static int mysetenv(char *name, char *value, int overwrite); +static int myunsetenv(char *name); +static int mysetenv(char *name, char *value, int overwrite) { + char *s; + char *orig; + s = (char *)getenv(name); + if ((s == NULL) || overwrite) { + s = (char *) mymalloc(strlen(name)+strlen(value)+5); + if (s == 0) { fprintf(stderr,"No more memory.\n"); exit(10); } + strcpy(s,name); + strcat(s,"="); strcat(s,value); + return(putenv(s)); + } + return (0); +} + +/* bug on Solaris. It does not unsetenv. + libc4, libc5, glibc. It does unsetenv. */ +static myunsetenv(char *name) { + return(putenv(name)); +} + /* Example. [(export) (PATH) (=) (/usr/new/bin:$PATH)] */ static struct object oxsSetenv(struct object ob) { struct object rob; @@ -197,9 +219,10 @@ static struct object oxsSetenv(struct object ob) { /* printf("%s\n",new); */ new = oxEvalEnvVar(new); /* printf("%s\n",new); */ - r = setenv(envp,new,1); + r = mysetenv(envp,new,1); }else{ - unsetenv(envp); r = 0; + myunsetenv(envp); r = 0; + /* bug: On Solaris, unsetenv will not work. */ } if (r != 0) errorKan1("%s\n","setenv failed."); new = (char *) getenv(envp); @@ -420,12 +443,18 @@ int oxsFileToVar(char *v,char *fname) { int limit; int c,i; - if (v == NULL) errorKan1("%s\n","oxsFileToVar(), v is NULL."); + if (v == NULL) { + /* errorKan1("%s\n","oxsFileToVar(), v is NULL."); */ + fprintf(stderr,"oxsFileToVar(), v is NULL."); + return(-1); + } limit = 1024; fp = fopen(fname,"r"); if (fp == NULL) { fprintf(stderr,"Filename=%s\n",fname); - errorKan1("%s\n","oxsFileToVar(), the file cannot be opened."); + /* errorKan1("%s\n","oxsFileToVar(), the file cannot be opened."); */ + fprintf(stderr,"oxsFileToVar(), the file cannot be opened."); + return(-1); } s = (char *)mymalloc(limit); if (s == NULL) errorKan1("%s\n","No more memory in oxsFileToVar()."); @@ -533,6 +562,7 @@ static struct object oxsExecuteBlocked(struct object o { int r,i,n; char **argv; + int errorf; argv = oxsBuildArgv(ob); argv = oxsBuildArgvRedirect(argv); @@ -545,9 +575,12 @@ static struct object oxsExecuteBlocked(struct object o errorKan1("%s\n","ForkExecBlocked failed."); } */ + errorf=0; if (AfterPt > 0) { for (i=0; i< AfterPt; i++) { - oxsFileToVar(AfterSetVar[i],AfterReadFile[i]); + if (oxsFileToVar(AfterSetVar[i],AfterReadFile[i]) != 0) { + errorf=1; + } } } AfterPt = 0; @@ -560,6 +593,7 @@ static struct object oxsExecuteBlocked(struct object o } } AfterD = 0; + if (errorf) errorKan1("%s\n","Some errors in oxsFileToVar()."); return(KpoInteger(r)); }