Subversion Repositories wimsdev

Rev

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