Subversion Repositories wimsdev

Rev

Rev 8149 | Rev 8900 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
  2.  *
  3.  *  This program is free software; you can redistribute it and/or modify
  4.  *  it under the terms of the GNU General Public License as published by
  5.  *  the Free Software Foundation; either version 2 of the License, or
  6.  *  (at your option) any later version.
  7.  *
  8.  *  This program is distributed in the hope that it will be useful,
  9.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  *  GNU General Public License for more details.
  12.  *
  13.  *  You should have received a copy of the GNU General Public License
  14.  *  along with this program; if not, write to the Free Software
  15.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17.  
  18. /* Common routines in interfaces */
  19. #include "common.h"
  20. #define ch_root "bin/ch..root"
  21.  
  22. int mypid;
  23. int must_chroot=0;
  24. char inputfname[256], outputfname[256];
  25. char pidfname[256];
  26. char parmbuf[parmlim+16];
  27. char *inpf, *outpf, *errorf;
  28. char *parm;
  29. char *tmp_dir;
  30. char cmdbuf[1024];
  31. char inputbuf[inputlim];
  32. char *inputptr, *inputend;
  33. char stdinbuf[MAX_LINELEN+1];
  34. char *cmdparm;
  35. int isabout=0;
  36. char *multiexec_random;
  37. int multiexec=0, mxpid, notfirst;
  38. int pipe_in[2], pipe_out[2];
  39. int debug=0;
  40. FILE *goin;
  41. unsigned int seed; /* random seed value */
  42. char aboutbuf[aboutlen];
  43. /* this is only a default. It should usually be reset. */
  44. char *tmpdir="/tmp";
  45. char startstring[256], endstring[256];
  46. char *obuf;
  47.  
  48. void check_parm(char *p);
  49. void output(char *p);
  50. void about(void);
  51. char *dynsetup(char *p, char *end);
  52.  
  53. /* Find first occurrence of word */
  54. char *wordchr2(char *p, char *w)
  55. {
  56.     char *r;
  57.  
  58.     if(*w==0) return NULL;
  59.     for(r=strstr(p,w);r!=NULL &&
  60.       ( (r>p && !isspace(*(r-1))) || (!isspace(*(r+strlen(w))) && *(r+strlen(w))!=0) );
  61.       r=strstr(r+1,w));
  62.     return r;
  63. }
  64.  
  65. /* find matching parenthesis */
  66. char *find_matching2(char *p, char c)
  67. {
  68.     char *pp;
  69.     int parenth, brak, brace;
  70.     parenth=brak=brace=0;
  71.     for(pp=p; *pp!=0; pp++) {
  72.       switch(*pp) {
  73.           case '[': brak++; break;
  74.           case ']': brak--; break;
  75.           case '(': parenth++; break;
  76.           case ')': parenth--; break;
  77.           case '{': brace++; break;
  78.           case '}': brace--; break;
  79.           default: continue;
  80.       }
  81.       if(parenth<0 || brak<0 || brace<0) {
  82.           if(*pp!=c || parenth>0 || brak>0 || brace>0) return NULL;
  83.           else break;
  84.       }
  85.     }
  86.     if(*pp!=c) return NULL;
  87.     return pp;
  88. }
  89.  
  90. /* Read/write to a file with variable parms to print filename */
  91. void accessfile(char *content, char *type, char *s,...)
  92. {
  93.     va_list vp;
  94.     char buf[MAX_LINELEN+1];
  95.     FILE *f;
  96.     int l;
  97.  
  98.     va_start(vp,s);
  99.     vsnprintf(buf,sizeof(buf),s,vp);
  100.     va_end(vp);
  101.     f=fopen(buf,type); if(f==NULL) {
  102.       if(*type=='r') content[0]=0; return;
  103.     }
  104.     switch(*type) {
  105.       case 'a':
  106.       case 'w': {
  107.           l=strlen(content); fwrite(content,1,l,f); break;
  108.       }
  109.       case 'r': {
  110.           l=fread(content,1,MAX_LINELEN-1,f);
  111.           if(l>0 && l<MAX_LINELEN) content[l]=0;
  112.           else content[0]=0;
  113.           break;
  114.       }
  115.       default: {
  116.           content[0]=0; break;
  117.       }
  118.     }
  119.     fclose(f);
  120. }
  121.  
  122. void getstdin(void)
  123. {
  124.     char *p;
  125.     int i,j,k;
  126.     i=0; k=MAX_LINELEN; stdinbuf[0]=0;
  127.     do {
  128.       j=read(0,stdinbuf+i,k);
  129.       if(j<0 || j>k) exit(1);
  130.       i+=j; k-=j; stdinbuf[i]=0;
  131.       p=strstr(stdinbuf,multiexec_random);
  132.       if(p) {*p=0; break;}
  133.     }
  134.     while(k>0);
  135. }
  136.  
  137. /* add a pid to the list of running childs */
  138. void addpid(int pid)
  139. {
  140.     char buf[MAX_LINELEN+1], pidbuf[32];
  141.     int l;
  142.     snprintf(pidbuf,sizeof(pidbuf),"%u",pid);
  143.     accessfile(buf,"r",pidfname); l=strlen(buf);
  144.     if(l>=MAX_LINELEN-64) return;
  145.     if(wordchr2(buf,pidbuf)==NULL) {
  146.       snprintf(buf+l,sizeof(buf)-l," %s",pidbuf);
  147.       accessfile(buf,"w",pidfname);
  148.     }
  149. }
  150.  
  151. /* Remove a pidname to the list of running childs */
  152. void rmpid(int pid)
  153. {
  154.     char buf[MAX_LINELEN+1], pidbuf[32], *p;
  155.     snprintf(pidbuf,sizeof(pidbuf),"%u",pid);
  156.     accessfile(buf,"r",pidfname);
  157.     p=wordchr2(buf,pidbuf);
  158.     if(p!=NULL) {
  159.       ovlstrcpy(p,find_word_start(find_word_end(p)));
  160.       accessfile(buf,"w",pidfname);
  161.     }
  162. }
  163.  
  164. int execredirected(char *cmdf, char *inf, char *outf, char *errf, char *args)
  165. {
  166.     pid_t pid;
  167.     int i;
  168.     struct stat st;
  169.     char *cm, *p, *p2, abuf[MAX_LINELEN+1];
  170.     char *arg[1024];
  171.  
  172.     for(cm=cmdf; isspace(*cm); cm++){};
  173.     if(*cmdf==0) return -1;
  174.     fflush(NULL);
  175. /* flush all output streams before forking
  176.  * otherwise they will be doubled */
  177.     pid=fork(); if(pid==-1) return -1;
  178.     if(!pid) { /* child */
  179.       if(!inf) {
  180.           dup2(pipe_in[0],0); close(pipe_in[1]);
  181.       }
  182.       else if (freopen(inf,"r",stdin) == NULL)
  183.             fprintf(stderr,"freopen failed");
  184.       if(!outf) {
  185.           dup2(pipe_out[1],1); close(pipe_out[0]);
  186.       }
  187.       else if (freopen(outf,"w",stdout) == NULL)
  188.             fprintf(stderr,"freopen failed");
  189.       if(errf && freopen(errf,"w",stderr) == NULL)
  190.             fprintf(stderr,"freopen failed");
  191.       snprintf(abuf,sizeof(abuf),"%s",find_word_start(args));
  192.       if(stat("../chroot/tmp/sessions/.chroot",&st)==0 || must_chroot) {
  193.           arg[0]=ch_root; i=1;
  194.       }
  195.       else {
  196.           i=0;
  197.           setreuid(getuid(),getuid());setregid(getgid(),getgid());
  198.       }
  199.       arg[i++]=cmdf;
  200.       for(p=abuf; *p && i<1000; i++, p=find_word_start(p2)) {
  201.           arg[i]=p; p2=find_word_end(p); if(*p2) *p2++=0;
  202.       }
  203.       arg[i]=NULL;
  204.       if(strchr(arg[0],'/')) execv(arg[0],arg);
  205.       else execvp(arg[0],arg);
  206.       fprintf(stderr,"%s not_INStalled",progname);
  207.       exit(127);
  208.     }
  209.     else { /* parent */
  210.       addpid(pid); mxpid=pid;
  211.       if(outf) {
  212.           int status;
  213.           close(pipe_in[1]);
  214.           if(waitpid(pid,&status,0)==pid) {
  215.             rmpid(pid); mxpid=-1;
  216.           }
  217.       }
  218.     }
  219.     return 0;
  220. }
  221.  
  222. /* verify illegal strings in parms. */
  223. void find_illegal(char *p)
  224. {
  225.     char *pp, *pe;
  226.     int i, l;
  227.     for(pp=p;*pp;pp++) {
  228.       if((*pp<' ' && *pp!='\n' && *pp!='        ') || *pp>=127) *pp=' ';
  229.     }
  230.     for(i=0;i<illpart_no;i++) {
  231.       pe=illpart[i]; l=strlen(pe);
  232.       for(pp=strstr(p,pe); pp; pp=strstr(pp+1,pe)) {
  233.           if(!isupper(pe[0]) || !islower(*(pp+l))) {
  234.             if(pp[1]!='j' && pp[1]!='J') pp[1]='J';
  235.             else pp[1]='Z';
  236.           }
  237.       }
  238.     }
  239.     for(i=0;i<illegal_no;i++) {
  240.       pe=illegal[i]; l=strlen(pe);
  241.       for(pp=strstr(p,pe); pp; pp=strstr(pp+1,pe)) {
  242.           if((pp==p || !isalnum(*(pp-1))) && !isalnum(*(pp+l))) {
  243.             if(pp[1]!='j' && pp[1]!='J') pp[1]='J';
  244.             else pp[1]='Z';
  245.           }
  246.       }
  247.     }
  248. }
  249.  
  250. /* strip trailing zeros */
  251. void strip_zeros(char *p)
  252. {
  253.     char *pp, *p2, *numend, *ee;
  254.     int i;
  255.     for(pp=p;*pp!=0;pp++) {
  256.       if(!isdigit(*pp)) continue;
  257.       i=0;
  258.       for(numend=pp;isdigit(*numend) || *numend=='.';numend++)
  259.         if(*numend=='.') i=1;
  260.       if(i==0) {
  261.           pp=numend-1;continue;
  262.       }
  263.       for(p2=numend;p2>pp && *(p2-1)=='0';p2--);
  264.       for(ee=numend;isspace(*ee);ee++);
  265.       if(*(pp+1)=='.' && (*ee=='E' || *ee=='e')
  266.          && *(ee+1)=='-') {
  267.           int k=0;
  268.           char *pt=ee+2;
  269.           while(isdigit(*pt)) {
  270.             k*=10;k+=*pt-'0';pt++;
  271.           }
  272.           if(precision>8 && (k>precision*2 || (k>precision && *pp=='0'))) {
  273.  
  274.             sprintf(pp,"0.0%s",pt);
  275.  
  276.             pp+=strlen("0.0")-1;
  277.             continue;
  278.           }
  279.       }
  280.  
  281.       if(*(p2-1)=='.' && p2<numend) p2++;
  282.  
  283.       if(p2<numend) {
  284.           ovlstrcpy(p2,numend);numend=p2;
  285.       }
  286.       pp=numend-1;
  287.     }
  288. }
  289.  
  290. char *hname[]={"", "_1","_2","_3","_4","_5","_6","_7","_8"};
  291. #define hnameno (sizeof(hname)/sizeof(hname[0]))
  292.  
  293. void putheader(void)
  294. {
  295.     char hbuf[64];
  296.     char *p;
  297.     int i;
  298.  
  299.     inputptr=dynsetup(inputptr,inputend);
  300.     snprintf(inputptr,inputend-inputptr,"%s",header);
  301.     inputptr+=strlen(inputptr);
  302.     for(i=0;i<hnameno;i++) {
  303.       snprintf(hbuf,sizeof(hbuf),"w_%s_header%s",progname,hname[i]);
  304.       p=getenv(hbuf); if(p!=NULL && *p!=0) {
  305.           snprintf(parmbuf,parmlim,"%s",p);
  306.           check_parm(parmbuf);
  307.           snprintf(inputptr,inputend-inputptr,"%s\n",parmbuf);
  308.           inputptr+=strlen(inputptr);
  309.       }
  310.     }
  311. }
  312.  
  313. void putparm(void)
  314. {
  315.     snprintf(parmbuf,parmlim,"%s",parm); check_parm(parmbuf);
  316.     snprintf(inputptr,inputend-inputptr,stringprinter,startstring);
  317.     inputptr+=strlen(inputptr);
  318.     snprintf(inputptr,inputend-inputptr,"%s",parmbuf);
  319.     inputptr+=strlen(inputptr);
  320.     if(inputptr<inputend && inputptr>inputbuf && inputptr[-1]!='\n')
  321.       *inputptr++='\n';
  322.     snprintf(inputptr,inputend-inputptr,stringprinter,endstring);
  323.     inputptr+=strlen(inputptr);
  324.     *inputptr=0;
  325. }
  326.  
  327. /* general first preparation */
  328. void prepare1(void)
  329. {
  330.     char *p, buf[256];
  331.     int i;
  332.     unsigned int r[4];
  333.     struct timeval t;
  334.  
  335.     parm=getenv("wims_exec_parm");
  336. /* nothing to do if no calling parameter */
  337.     if(parm==NULL || *parm==0) exit(0);
  338.     inputptr=inputbuf; inputend=inputbuf+inputlim-1;
  339.     multiexec_random=getenv("multiexec_random");
  340.     if(multiexec_random==NULL) multiexec_random="";
  341.     if(*parm && strcmp(parm,multiexec_random)==0) {
  342.       multiexec=1;
  343.       getstdin(); parm=stdinbuf;
  344.       if(parm[0]==0) exit(0);
  345.     }
  346.     if(pipe(pipe_in)<0 || pipe(pipe_out)<0) {
  347.       fprintf(stderr,"%s: unable to create pipe.\n",progname);
  348.       exit(1);
  349.     }
  350. /*    i=fcntl(pipe_in[1],F_GETFL); if(i>=0) fcntl(pipe_in[1],F_SETFL,i|O_NONBLOCK);
  351.     i=fcntl(pipe_out[0],F_GETFL); if(i>=0) fcntl(pipe_out[0],F_SETFL,i|O_NONBLOCK);
  352. */    tmp_dir=getenv("tmp_dir"); if(tmp_dir==NULL || *tmp_dir==0) tmp_dir=tmpdir;
  353.     setenv("TMPDIR",tmp_dir,1);
  354.     mypid=getpid();
  355.     gettimeofday(&t,NULL); seed=t.tv_usec*t.tv_sec+mypid;
  356.     srandom(seed);
  357.     for(i=0;i<4;i++) r[i]=random();
  358.     snprintf(startstring,sizeof(startstring),
  359.            "Start line %s %u %u %u %u",progname,r[0],r[1],r[2],r[3]);
  360.     snprintf(endstring,sizeof(endstring),
  361.            "End line %s %u %u %u %u",progname,r[0],r[1],r[2],r[3]);
  362.     snprintf(buf,sizeof(buf),"%s_command",progname); p=getenv(buf);
  363.     if(p!=NULL && *find_word_start(p)!=0) nameofcmd=find_word_start(p);
  364.     snprintf(cmdbuf,sizeof(cmdbuf),"%s",nameofcmd); nameofcmd=cmdbuf;
  365.     cmdparm=find_word_end(nameofcmd); if(*cmdparm) *cmdparm++=0;
  366.     cmdparm=find_word_start(cmdparm);
  367.     snprintf(pidfname,sizeof(pidfname),"%s/exec.pid",tmp_dir); addpid(mypid);
  368.     snprintf(inputfname,sizeof(inputfname),"%s/%s_input.%d",tmp_dir,progname,mypid);
  369.     snprintf(outputfname,sizeof(outputfname),"%s/%s_output.%d",tmp_dir,progname,mypid);
  370.     errorf=NULL;
  371.     inpf=inputfname; outpf=outputfname;
  372.     isabout=0; p=find_word_start(parm); i=strlen("about");
  373.     if(memcmp(p,"about",i)==0 && *find_word_start(p+i)==0) isabout=1;
  374.     p=getenv("multiexec_debug"); if(p && strcmp(p,"yes")==0) debug=1;
  375. }
  376.  
  377. void prepabout(char *cmd, char *outf, char *errf)
  378. {
  379.     (void)write(pipe_in[1],cmd,strlen(cmd));
  380.     execredirected(nameofcmd,NULL,outf,errf,cmdparm);
  381. }
  382.  
  383. /* read to aboutbuf. Returns content length. */
  384. int readabout(void)
  385. {
  386.     FILE *ff;
  387.     long int l;
  388.     char *p;
  389.  
  390.     aboutbuf[0]=0; ff=fopen(outputfname,"r");
  391.     if(ff!=NULL) {
  392.       fseek(ff,0,SEEK_END); l=ftell(ff); fseek(ff,0,SEEK_SET);
  393.       l=fread(aboutbuf,1,aboutlen-10,ff); fclose(ff);
  394.       if(l>0 && l<aboutlen) aboutbuf[l]=0; else aboutbuf[0]=0;
  395.       p=find_word_start(aboutbuf); if(p>aboutbuf) ovlstrcpy(aboutbuf,p);
  396.     }
  397.     return strlen(aboutbuf);
  398. }
  399.  
  400. /* read result of execution */
  401. void readresult(void)
  402. {
  403.     FILE *ff;
  404.     char *p, *pp, *pe;
  405.  
  406.     if(debug) {
  407.       ff=fopen(outputfname,"a"); if(ff) {
  408.           fputs(obuf,ff); fclose(ff);
  409.       }
  410.     }
  411.     pe=NULL;
  412.     p=strstr(obuf,startstring);
  413.     if(p) {
  414.       p+=strlen(startstring);
  415.       pe=strstr(p,endstring);
  416.       if(pe) {
  417.           for(pp=pe-1; pp>=p && pp>pe-64 && *pp!='\n'; pp--);
  418.           if(pp>=p && *pp=='\n') pe=pp;
  419.       }
  420.     }
  421.     if(pe) {
  422.       *pe=0;
  423.       while((pe=strstr(p,startstring))!=NULL) {
  424.           p=pe+strlen(startstring);
  425.       }
  426.       output(p);
  427.     }
  428.     else {
  429.       if(mxpid>=0) {
  430.           if(kill(mxpid,0)<0 && errno==ESRCH) { /* this doesn't work */
  431.             fprintf(stderr,"%s not_INStalled",progname);
  432.           }
  433.           else {
  434.             fprintf(stderr,"%s: execution error or time out.\n",progname);
  435.             kill(mxpid,SIGKILL);
  436.           }
  437.           rmpid(mxpid); mxpid=-1;
  438.       }
  439.       else {
  440.           fprintf(stderr,"%s: aborted on earlier error.\n",progname);
  441.       }
  442.     }
  443.     if(multiexec && *multiexec_random) printf("%s\n",multiexec_random);
  444.     fflush(stdout);
  445. }
  446.  
  447. #ifdef linebyline1
  448.  
  449. /* this one is for maxima but not used */
  450. void dopipes(void)
  451. {
  452.     long int i, l;
  453.     char *outptr;
  454.     char *p1, *p2, *pp, *pe;
  455.     struct timeval t;
  456.     fd_set rset;
  457.  
  458.     if(mxpid<0) {
  459.       *obuf=0; return;
  460.     }
  461.     outptr=obuf; pp=pe=NULL;
  462.     for(p1=ibuf; *p1; p1=p2) {
  463.       p2=strchr(p1,'\n'); if(p2) p2++; else p2=p1+strlen(p1);
  464.       write(pipe_in[1],p1,p2-p1);
  465.  
  466.       if(strstr(p1,startstring)!=NULL) iactive=1;
  467.       reread:
  468.       l=read(fifofd2,lp,MAX_LINELEN-(lp-lbuf));
  469.       if(!iactive) continue;
  470.       if(l<0 || l>MAX_LINELEN-(lp-lbuf)) l=0;
  471.       lp+=l; *lp=0;
  472.       if(active==0) {
  473.           char *pp;
  474.           pp=strstr(lbuf,startstring);
  475.           if(pp!=NULL) {
  476.             active=1; ovlstrcpy(lbuf,pp); lp=lbuf+strlen(lbuf);
  477.           }
  478.       }
  479.       if(active!=0 && strstr(lbuf,linebyline)!=NULL) {
  480.           fprintf(ff,"%s",lbuf); lp=lbuf;
  481.           if(strstr(lbuf,endstring)!=NULL) {lbuf[0]=0; active=-1; break;}
  482.           lbuf[0]=0; continue;
  483.       }
  484. /* time out allowance between each silence */
  485.       t.tv_sec=3; t.tv_usec=400000;
  486.       i=select(fifofd2+1,&rset,NULL,NULL,&t);
  487.       if(i>0) goto reread;
  488.       else break; /* time out or error */
  489.     }
  490. }
  491.  
  492. #else
  493.  
  494. void dopipes(void)
  495. {
  496.     long int i, k, l;
  497.     int interval=20000; /* in microseconds */
  498.     int timeout =300; /* in intervals */
  499.     char *outptr;
  500.     char *p1, *p2, *inp, *pw;
  501.     struct timeval t;
  502.     fd_set rset, wset;
  503.  
  504.     *obuf=0; if(mxpid<0) return;
  505.     outptr=obuf; inp=inputbuf; k=0;
  506.     while(inp<inputptr) {
  507.       t.tv_sec=0; t.tv_usec=interval;
  508.       FD_ZERO(&rset); FD_SET(pipe_out[0],&rset);
  509.       FD_ZERO(&wset); FD_SET(pipe_in[1],&wset);
  510.       i=pipe_out[0]; if(i<pipe_in[1]) i=pipe_in[1];
  511.       i=select(i+1,&rset,&wset,NULL,&t);
  512.       if(i<=0) {
  513.           k++; if(k>=timeout) return; /* time out */
  514.       }
  515.       if(FD_ISSET(pipe_in[1],&wset)) {
  516. /* Writing must be line by line, for otherwise
  517.  * it will block when the input is large. */
  518.           for(pw=inp; pw<inputptr && *pw!='\n'; pw++);
  519.           if(pw<inputptr) pw++;
  520.           l=write(pipe_in[1],inp,pw-inp);
  521.           if(l<0 || l>inputptr-inp) return;
  522.           inp+=l;
  523.       }
  524.       if(FD_ISSET(pipe_out[0],&rset)) {
  525.           l=read(pipe_out[0],outptr,fsizelim-(outptr-obuf)-1);
  526.           if(l<=0 || l>fsizelim-(outptr-obuf)-1) {
  527.             *outptr=0; break;
  528.           }
  529.           outptr+=l; *outptr=0;
  530.       }
  531.     }
  532.     p2=NULL;
  533.     p1=strstr(obuf,startstring);
  534.     if(p1) {
  535.       p1+=strlen(startstring);
  536.       p2=strstr(p1,endstring);
  537.     }
  538.     while(!p2) {
  539.       t.tv_sec=0; t.tv_usec=interval;
  540.       FD_ZERO(&rset); FD_SET(pipe_out[0],&rset);
  541.       i=select(pipe_out[0]+1,&rset,NULL,NULL,&t);
  542.       if(i>0) {
  543.           l=read(pipe_out[0],outptr,fsizelim-(outptr-obuf)-1);
  544.           if(l<=0 || l>fsizelim-(outptr-obuf)-1) {
  545.             *outptr=0; break;
  546.           }
  547.           outptr+=l; *outptr=0;
  548.       }
  549.       else {
  550.           k++; if(k>=timeout) break;
  551.       }
  552.       if(!p1) {
  553.           p1=strstr(obuf,startstring);
  554.           if(p1) p1+=strlen(startstring);
  555.       }
  556.       if(p1) p2=strstr(p1,endstring);
  557.     }
  558. }
  559.  
  560. #endif
  561.  
  562. void run(void)
  563. {
  564.     FILE *ff;
  565.  
  566.     if(isabout) {about(); goto end;}
  567.     execredirected(nameofcmd,NULL,NULL,NULL,cmdparm);
  568.     putheader();
  569.     obuf=xmalloc(fsizelim); if(!obuf) return;
  570.     rep:
  571.     putparm();
  572.     if(!multiexec) {
  573.       snprintf(inputptr,inputend-inputptr,"%s",quitstring);
  574.       inputptr+=strlen(inputptr);
  575.     }
  576.     if(debug) {
  577.       ff=fopen(inputfname,"a"); if(ff) {
  578.           fputs(inputbuf,ff); fclose(ff);
  579.       }
  580.     }
  581.     dopipes();
  582.     readresult();
  583.     if(multiexec) {
  584.       getstdin(); inputptr=inputbuf; inputbuf[0]=0;
  585.       goto rep;
  586.     }
  587.     end: if(strstr(tmp_dir,"tmp/sessions/")==NULL) {
  588.       unlink(inputfname); unlink(outputfname);
  589.     }
  590.     free(obuf); rmpid(mypid);
  591.     if(mxpid>0) {kill(mxpid,SIGKILL); rmpid(mxpid);}
  592. }
  593.  
  594.