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 |
|
42 | int l, *ip; |
43 |
|
43 | if(answerlen<0) l=strlen(textbuf); else l=answerlen; |
44 |
|
44 | ip=(int *) commbuf; *ip=l; |
45 |
|
45 | (void)write(fh,commbuf,l+sizeof(int)); |
46 |
|
46 | close(fh); |
47 |
|
47 | if(debugging) { |
48 |
|
48 | if(textbuf[0]=='O') debug("%.2s %d bytes.",textbuf,l); |
49 |
|
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 |
|
55 | char *estr, buf[MAX_LINELEN+1]; |
56 |
|
56 | va_list vp; |
57 |
|
57 | va_start(vp,p); |
58 |
|
58 | vsnprintf(buf,sizeof(buf),p,vp); |
59 |
|
59 | va_end(vp); |
60 |
|
60 | if(errno==0) estr=""; else estr=strerror(errno); |
61 |
|
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 |
|
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 |
|
71 | int t,l, *ip; |
72 | 72 | ||
73 |
|
73 | t=read(fh,commbuf,BUFFERLEN-sizeof(int)); if(t<sizeof(int)) { |
74 |
|
74 | bad: sockerror(3,"Daemon socket read error."); |
75 |
|
75 | goto end; |
76 |
|
76 | } |
77 |
|
77 | ip=(int *) commbuf; l=*ip; |
78 |
|
78 | if(l<=0 || l>=BUFFERLEN-sizeof(int)) goto bad; |
79 |
|
79 | while(t<l+sizeof(int)) { |
80 |
|
80 | struct timeval tv; |
81 |
|
81 | fd_set rset; |
82 |
|
82 | int t2; |
83 |
|
83 | tv.tv_sec=0; tv.tv_usec=20*1000; |
84 |
|
84 | FD_ZERO(&rset); FD_SET(fh,&rset); |
85 |
|
85 | if(select(fh+1,&rset,NULL,NULL,&tv)<=0) goto bad; |
86 |
|
86 | t2=read(fh,commbuf+t,l+sizeof(int)-t); |
87 |
|
87 | if(t2<=0 || t2>l+sizeof(int)-t) goto bad; |
88 |
|
88 | t+=t2; |
89 |
|
89 | } |
90 |
|
90 | textbuf[l]=0; textptr=textbuf; |
91 |
|
91 | answerlen=-1; |
92 |
|
92 | if(debugging) debug("> %s",textbuf); |
93 |
|
93 | if(options()>=0) cmd(); |
94 |
|
94 | end: (void)chdir(cwd); cwdtype=dir_home; output(fh); |
95 | } |
95 | } |