Back to index

wims  3.65+svn20090927
Functions | Variables
lines.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void accessfile (char *content, char *type, char *s,...)
int execredirected (char *cmdf, char *inf, char *outf, char *errf, char *arg[])
int call_ssh (int wait, char *s,...)
int call_sh (int wait, char *s,...)
void error (char *msg)
void debug (char *p,...)

Variables

int exec_wait

Function Documentation

void accessfile ( char *  content,
char *  type,
char *  s,
  ... 
)
int call_sh ( int  wait,
char *  s,
  ... 
)

Definition at line 159 of file lines.c.

{
    va_list vp;
    char buf[MAX_LINELEN+1];
    char *abuf[8];

    va_start(vp,s);
    vsnprintf(buf,sizeof(buf),s,vp);
    va_end(vp);
    abuf[0]="sh"; abuf[1]="-c"; abuf[2]=buf; abuf[3]=NULL;
    exec_wait=wait;
    return execredirected(abuf[0],NULL,NULL,NULL,abuf);
}

Here is the call graph for this function:

int call_ssh ( int  wait,
char *  s,
  ... 
)

Definition at line 72 of file lines.c.

{
    va_list vp;
    char buf[MAX_LINELEN+1];
    char *arg[1024];
    char *inf=NULL, *outf=NULL, *errf=NULL;
    char *cmdf, *p, *p2;
    int i, d;

    va_start(vp,s);
    vsnprintf(buf,sizeof(buf),s,vp);
    va_end(vp);
    p=find_word_start(buf); if(*p==0) return 0;
    cmdf=p;
    for(i=0;*p!=0 && i<1000; p=find_word_start(p2)) {
       switch(*p) {
           case '\'': {
              p++; p2=strchr(p,'\''); if(p2==NULL) p2=p+strlen(p);
              d=0; break;
           }
           case '"': {
              p++; p2=strchr(p,'"'); if(p2==NULL) p2=p+strlen(p);
              d=0; break;
           }
           default: d=1; p2=find_word_end(p); break;
       }
       if(*p2) *p2++=0;
       if(!d) {arg[i++]=p; continue;}
       switch(*p) {
           case '<': inf=++p; break;
           case '>': {
              p++; if(*p=='&') {
                  merge: p++; errf=outf=p; break;
              }
              else outf=p;
              break;
           }
           case '&': {
              p++; if(*p=='>') goto merge;
              else break;
           }
           case '2': {
              if(*(p+1)=='>') {errf=p+2; break;}
           }
           default: arg[i++]=p; break;
       }
    }
    arg[i]=NULL;
    exec_wait=wait;
    return execredirected(cmdf,inf,outf,errf,arg);
}

Here is the call graph for this function:

void debug ( char *  p,
  ... 
)

Definition at line 178 of file lines.c.

{
    char lbuf[MAX_LINELEN+1];
    char *pp;
    va_list vp;
    
    snprintf(lbuf,sizeof(lbuf),"%s: ",nowstr);
    pp=lbuf+strlen(lbuf);
    va_start(vp,p);
    vsnprintf(pp,sizeof(lbuf)-(pp-lbuf),p,vp);
    va_end(vp);
    pp=strchr(lbuf,'\n'); if(pp) *pp=0;
    strip_trailing_spaces(lbuf); strcat(lbuf,"\n");
    accessfile(lbuf,"a",debugfile);    
}

Here is the call graph for this function:

void error ( char *  msg)

Definition at line 173 of file lines.c.

{
    fprintf(stderr,"%s %s\n",nowstr, msg);
}
int execredirected ( char *  cmdf,
char *  inf,
char *  outf,
char *  errf,
char *  arg[] 
)

Definition at line 24 of file lines.c.

{
    pid_t pid;
    int status, t;

    fflush(NULL);    /* flush all output streams before forking
                      * otherwise they will be doubled */
    pid=fork(); if(pid==-1) return -1;
    if(!pid) {       /* child */
       char buf[4096]; int k;
       if(inf!=NULL) freopen(inf,"r",stdin);
       if(outf!=NULL) freopen(outf,"w",stdout);
       if(errf!=NULL) freopen(errf,"w",stderr);
              /* This is to patch LinuxPPC uid wrapping 
               * for scripts */
       t=0; if(strchr(cmdf,'/')) {
           FILE *tf;
           char buf[16];
           tf=fopen(cmdf,"r"); fread(buf,1,10,tf); fclose(tf);
           if(memcmp(buf+1,"ELF",3)!=0) t=1;
       }
       errno=0;
       if(strchr(cmdf,'/')) execve(cmdf,arg,environ);
       else execvp(cmdf,arg);
       snprintf(buf,sizeof(buf),"Failed to execute");
       for(k=0;arg[k];k++) {
           t=strlen(buf);
           snprintf(buf+t,sizeof(buf)-t," %s",arg[k]);
       }
       t=strlen(buf);
       snprintf(buf+t,sizeof(buf)-t,"\n   %s\n",strerror(errno));
       accessfile(buf,"a","%s/exec.fail",tmpd);
       exit(127);
    }
    else {    /* parent */
       status=0;
       if(exec_wait) {
           waitpid(pid,&status,0);
           return WEXITSTATUS(status);
       }
       else {
           exec_wait=1; addfork(pid,0); return 0;
       }
    }
}

Here is the call graph for this function:


Variable Documentation

int exec_wait

Definition at line 20 of file lines.c.