Subversion Repositories wimsdev

Rev

Rev 8849 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8849 Rev 12472
Line 37... Line 37...
37
    if(listen(commsock,SOCKET_QUEUE)==-1) errorquit("listen() error.");
37
    if(listen(commsock,SOCKET_QUEUE)==-1) errorquit("listen() error.");
38
}
38
}
39
 
39
 
40
void output(int fh)
40
void output(int fh)
41
{
41
{
42
    int l, *ip;
42
  int l, *ip;
43
    if(answerlen<0) l=strlen(textbuf); else l=answerlen;
43
  if(answerlen<0) l=strlen(textbuf); else l=answerlen;
44
    ip=(int *) commbuf; *ip=l;
44
  ip=(int *) commbuf; *ip=l;
45
    (void)write(fh,commbuf,l+sizeof(int));
45
  (void)write(fh,commbuf,l+sizeof(int));
46
    close(fh);
46
  close(fh);
47
    if(debugging) {
47
  if(debugging) {
48
      if(textbuf[0]=='O') debug("%.2s %d bytes.",textbuf,l);
48
    if(textbuf[0]=='O') debug("%.2s %d bytes.",textbuf,l);
49
      else debug("%s",textbuf);
49
    else debug("%s",textbuf);
50
    }
50
  }
51
}
51
}
52
 
52
 
53
void sockerror(int type, char *p,...)
53
void sockerror(int type, char *p,...)
54
{
54
{
55
    char *estr, buf[MAX_LINELEN+1];
55
  char *estr, buf[MAX_LINELEN+1];
56
    va_list vp;
56
  va_list vp;
57
    va_start(vp,p);
57
  va_start(vp,p);
58
    vsnprintf(buf,sizeof(buf),p,vp);
58
  vsnprintf(buf,sizeof(buf),p,vp);
59
    va_end(vp);
59
  va_end(vp);
60
    if(errno==0) estr=""; else estr=strerror(errno);
60
  if(errno==0) estr=""; else estr=strerror(errno);
61
    snprintf(textbuf,BUFFERLEN-16,"ERROR %d\n%s\n%s",type,buf,estr);
61
  snprintf(textbuf,BUFFERLEN-16,"ERROR %d\n%s\n%s",type,buf,estr);
62
}
62
}
63
 
63
 
64
void sockok(char *p)
64
void sockok(char *p)
65
{
65
{
66
    snprintf(textbuf,BUFFERLEN-16,"OK\n%s",p);
66
  snprintf(textbuf,BUFFERLEN-16,"OK\n%s",p);
67
}
67
}
68
 
68
 
69
void answer(int fh)
69
void answer(int fh)
70
{
70
{
71
    int t,l, *ip;
71
  int t,l, *ip;
72
 
72
 
73
    t=read(fh,commbuf,BUFFERLEN-sizeof(int)); if(t<sizeof(int)) {
73
  t=read(fh,commbuf,BUFFERLEN-sizeof(int)); if(t<sizeof(int)) {
74
      bad: sockerror(3,"Daemon socket read error.");
74
    bad: sockerror(3,"Daemon socket read error.");
75
      goto end;
75
    goto end;
76
    }
76
  }
77
    ip=(int *) commbuf; l=*ip;
77
  ip=(int *) commbuf; l=*ip;
78
    if(l<=0 || l>=BUFFERLEN-sizeof(int)) goto bad;
78
  if(l<=0 || l>=BUFFERLEN-sizeof(int)) goto bad;
79
    while(t<l+sizeof(int)) {
79
  while(t<l+sizeof(int)) {
80
      struct timeval tv;
80
    struct timeval tv;
81
      fd_set rset;
81
    fd_set rset;
82
      int t2;
82
    int t2;
83
      tv.tv_sec=0; tv.tv_usec=20*1000;
83
    tv.tv_sec=0; tv.tv_usec=20*1000;
84
      FD_ZERO(&rset); FD_SET(fh,&rset);
84
    FD_ZERO(&rset); FD_SET(fh,&rset);
85
      if(select(fh+1,&rset,NULL,NULL,&tv)<=0) goto bad;
85
    if(select(fh+1,&rset,NULL,NULL,&tv)<=0) goto bad;
86
      t2=read(fh,commbuf+t,l+sizeof(int)-t);
86
    t2=read(fh,commbuf+t,l+sizeof(int)-t);
87
      if(t2<=0 || t2>l+sizeof(int)-t) goto bad;
87
    if(t2<=0 || t2>l+sizeof(int)-t) goto bad;
88
      t+=t2;
88
    t+=t2;
89
    }
89
  }
90
    textbuf[l]=0; textptr=textbuf;
90
  textbuf[l]=0; textptr=textbuf;
91
    answerlen=-1;
91
  answerlen=-1;
92
    if(debugging) debug("> %s",textbuf);
92
  if(debugging) debug("> %s",textbuf);
93
    if(options()>=0) cmd();
93
  if(options()>=0) cmd();
94
    end: (void)chdir(cwd); cwdtype=dir_home; output(fh);
94
  end: (void)chdir(cwd); cwdtype=dir_home; output(fh);
95
}
95
}