| ... | ... |
@@ -114,16 +114,29 @@ uint32_t getrid() |
| 114 | 114 |
|
| 115 | 115 |
int workend(mcomm *c) |
| 116 | 116 |
{
|
| 117 |
- if(c){
|
|
| 118 |
- if(c->working && !c->cpid){
|
|
| 119 |
- c->working = 0; |
|
| 120 |
- if(moption.commpass && !c->authchk){
|
|
| 121 |
- cprintf(0, c, "password: \x1b]E"); |
|
| 122 |
- }else{
|
|
| 123 |
- cprintf(0,c,"> "); |
|
| 117 |
+ char *m; |
|
| 118 |
+ if(!c){
|
|
| 119 |
+ return(0); |
|
| 120 |
+ } |
|
| 121 |
+ if(!c->working){
|
|
| 122 |
+ return(0); |
|
| 123 |
+ } |
|
| 124 |
+ if(c->cpid){
|
|
| 125 |
+ return(0); |
|
| 126 |
+ } |
|
| 127 |
+ if(moption.commpass && !c->authchk){
|
|
| 128 |
+ m = "password: \x1b]E"; |
|
| 129 |
+ }else{
|
|
| 130 |
+ m = "> "; |
|
| 131 |
+ if(c->logover && strcmp("dsync", c->parse[0][0])){
|
|
| 132 |
+ if(cprintf(0, c, "[error] Log lost: %d line\n", c->logover) == 0){
|
|
| 133 |
+ c->logover = 0; |
|
| 124 | 134 |
} |
| 125 | 135 |
} |
| 126 | 136 |
} |
| 137 |
+ if(cprintf(0, c, m) == 0){
|
|
| 138 |
+ c->working = 0; |
|
| 139 |
+ } |
|
| 127 | 140 |
return(0); |
| 128 | 141 |
} |
| 129 | 142 |
|
| ... | ... |
@@ -327,7 +327,7 @@ char *stropcode(mdata *data); |
| 327 | 327 |
char *strackreq(mdata *data); |
| 328 | 328 |
void mprintf(int l, const char *func, mfile *m); |
| 329 | 329 |
void lprintf(int l, char *fmt, ...); |
| 330 |
-void cprintf(int l, mcomm *c, char *fmt, ...); |
|
| 330 |
+int cprintf(int l, mcomm *c, char *fmt, ...); |
|
| 331 | 331 |
void fdprintf(int s, char *fmt, ...); |
| 332 | 332 |
|
| 333 | 333 |
/*----- packet data access -----*/ |
| ... | ... |
@@ -177,49 +177,34 @@ void lprintf(int l, char *fmt, ...) |
| 177 | 177 |
m[0] = 0; |
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 |
-void cprintf(int l, mcomm *c, char *fmt, ...) |
|
| 180 |
+int cprintf(int l, mcomm *c, char *fmt, ...) |
|
| 181 | 181 |
{
|
| 182 | 182 |
int r; |
| 183 | 183 |
int n; |
| 184 |
- fd_set wfds; |
|
| 185 |
- struct timeval tv; |
|
| 186 | 184 |
char m[2048]; |
| 187 | 185 |
va_list arg; |
| 188 | 186 |
if(!c){
|
| 189 |
- return; |
|
| 187 |
+ return(0); |
|
| 190 | 188 |
} |
| 191 | 189 |
if(c->fd[0] == -1){
|
| 192 |
- return; |
|
| 190 |
+ return(0); |
|
| 193 | 191 |
} |
| 194 | 192 |
if(c->loglevel < l){
|
| 195 |
- return; |
|
| 193 |
+ return(0); |
|
| 196 | 194 |
} |
| 197 | 195 |
va_start(arg, fmt); |
| 198 | 196 |
vsnprintf(m, sizeof(m), fmt, arg); |
| 199 | 197 |
va_end(arg); |
| 200 | 198 |
m[sizeof(m) - 1] = 0; |
| 201 |
- FD_ZERO(&wfds); |
|
| 202 |
- FD_SET(c->fd[0], &wfds); |
|
| 203 |
- tv.tv_sec = 0; |
|
| 204 |
- tv.tv_usec = 100000; |
|
| 205 |
- if(select(1024, NULL, &wfds, NULL, &tv) <= 0){
|
|
| 206 |
- c->logover++; |
|
| 207 |
- lprintf(0, "[error] %s: client busy: %s", __func__, m); |
|
| 199 |
+ n = strlen(m); |
|
| 200 |
+ if(write(c->fd[0], m, n) == n){
|
|
| 201 |
+ fsync(c->fd[0]); |
|
| 208 | 202 |
}else{
|
| 209 |
- n = strlen(m); |
|
| 210 |
- r = write(c->fd[0], m, n); |
|
| 211 |
- if(r == -1){
|
|
| 212 |
- c->logover++; |
|
| 213 |
- lprintf(0, "[error] %s: write: %s fd=%d", __func__, strerror(errno), c->fd[0]); |
|
| 214 |
- }else{
|
|
| 215 |
- if(r < n){
|
|
| 216 |
- c->logover++; |
|
| 217 |
- lprintf(0, "[error] %s: over fllow: %s", __func__, m); |
|
| 218 |
- }else{
|
|
| 219 |
- fsync(c->fd[0]); |
|
| 220 |
- } |
|
| 221 |
- } |
|
| 203 |
+ c->logover++; |
|
| 204 |
+ lprintf(0, "[error] %s: Resource temporarily unavailable: %s", __func__, m); |
|
| 205 |
+ return(-1); |
|
| 222 | 206 |
} |
| 207 |
+ return(0); |
|
| 223 | 208 |
} |
| 224 | 209 |
|
| 225 | 210 |
void mprintf(int l, const char *func, mfile *m) |