Subversion Repositories wimsdev

Rev

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