Subversion Repositories wimsdev

Rev

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