| 132 |
log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno); |
log_error("epoll_ctl(STDOUT_FILENO) error (%d)\n", errno); |
| 133 |
if (close(stdout_epollfd) < 0) |
if (close(stdout_epollfd) < 0) |
| 134 |
{ |
{ |
| 135 |
log_error("close(stdout_epollfd) error (%d)\n"); |
log_error("close(stdout_epollfd) error (%d)\n", errno); |
| 136 |
} |
} |
| 137 |
stdout_epollfd = -1; |
stdout_epollfd = -1; |
| 138 |
return -1; |
return -1; |
| 214 |
|
|
| 215 |
if (close(stdout_epollfd) < 0) |
if (close(stdout_epollfd) < 0) |
| 216 |
{ |
{ |
| 217 |
log_error("close(stdout_epollfd) error (%d)\n"); |
log_error("close(stdout_epollfd) error (%d)\n", errno); |
| 218 |
} |
} |
| 219 |
stdout_epollfd = -1; |
stdout_epollfd = -1; |
| 220 |
} |
} |
| 243 |
ret = vsnprintf(buf, sizeof(buf), format, args); |
ret = vsnprintf(buf, sizeof(buf), format, args); |
| 244 |
va_end(args); |
va_end(args); |
| 245 |
|
|
| 246 |
if (ret > 0) |
if (ret >= 0) |
| 247 |
{ |
{ |
| 248 |
int written = (ret >= sizeof(buf) ? (int)sizeof(buf) - 1 : ret); |
int written = (ret >= sizeof(buf) ? (int)sizeof(buf) - 1 : ret); |
| 249 |
|
|
| 256 |
{ |
{ |
| 257 |
memcpy(stdout_buf + stdout_buf_len, buf, (size_t)written); |
memcpy(stdout_buf + stdout_buf_len, buf, (size_t)written); |
| 258 |
stdout_buf_len += written; |
stdout_buf_len += written; |
| 259 |
|
ret = written; |
| 260 |
} |
} |
| 261 |
else |
else |
| 262 |
{ |
{ |
| 263 |
errno = EAGAIN; |
errno = EAGAIN; |
| 264 |
int need = stdout_buf_len + ret - OUTPUT_BUF_SIZE; |
int need = stdout_buf_len + written - OUTPUT_BUF_SIZE; |
| 265 |
log_error("Output buffer is full, additional %d is required\n", need); |
log_error("Output buffer is full, additional %d bytes are required\n", need); |
| 266 |
|
ret = -need; |
| 267 |
} |
} |
| 268 |
} |
} |
| 269 |
|
|
| 1168 |
{ |
{ |
| 1169 |
if (errno == EINVAL) // Incomplete |
if (errno == EINVAL) // Incomplete |
| 1170 |
{ |
{ |
| 1171 |
log_debug("iconv(inbytes=%ld, outbytes=%ld) error: EINVAL, in_buf[0]=%d\n", in_bytes, out_bytes, in_buf[0]); |
log_debug("iconv(inbytes=%zu, outbytes=%zu) error: EINVAL, in_buf[0]=%d\n", |
| 1172 |
|
in_bytes, out_bytes, (unsigned char)in_buf[0]); |
| 1173 |
if (p_buf != in_buf) |
if (p_buf != in_buf) |
| 1174 |
{ |
{ |
| 1175 |
*p_buf_len -= (int)(in_buf - p_buf); |
*p_buf_len -= (int)(in_buf - p_buf); |
| 1182 |
} |
} |
| 1183 |
else if (errno == E2BIG) |
else if (errno == E2BIG) |
| 1184 |
{ |
{ |
| 1185 |
log_error("iconv(inbytes=%ld, outbytes=%ld) error: E2BIG\n", in_bytes, out_bytes); |
log_error("iconv(inbytes=%zu, outbytes=%zu) error: E2BIG\n", in_bytes, out_bytes); |
| 1186 |
return -1; |
return -1; |
| 1187 |
} |
} |
| 1188 |
else if (errno == EILSEQ) |
else if (errno == EILSEQ) |
| 1189 |
{ |
{ |
| 1190 |
if (in_bytes > out_bytes || out_bytes <= 0) |
if (in_bytes > out_bytes || out_bytes <= 0) |
| 1191 |
{ |
{ |
| 1192 |
log_error("iconv(inbytes=%ld, outbytes=%ld) error: EILSEQ and E2BIG\n", in_bytes, out_bytes); |
log_error("iconv(inbytes=%zu, outbytes=%zu) error: EILSEQ\n", in_bytes, out_bytes); |
| 1193 |
return -2; |
return -2; |
| 1194 |
} |
} |
| 1195 |
|
|
| 1197 |
if (in_bytes == 0) |
if (in_bytes == 0) |
| 1198 |
{ |
{ |
| 1199 |
in_bytes = (size_t)(*p_buf_len - *p_buf_offset); |
in_bytes = (size_t)(*p_buf_len - *p_buf_offset); |
| 1200 |
log_debug("Reset in_bytes from 0 to %ld\n", in_bytes); |
log_debug("Reset in_bytes from 0 to %zu\n", in_bytes); |
| 1201 |
} |
} |
| 1202 |
|
|
| 1203 |
log_debug("iconv(in_bytes=%ld, out_bytes=%ld) error: EILSEQ, in_buf[0]=%d\n", |
log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: EILSEQ, in_buf[0]=%d\n", |
| 1204 |
in_bytes, out_bytes, in_buf[0]); |
in_bytes, out_bytes, (unsigned char)in_buf[0]); |
| 1205 |
skip_current = 1; |
skip_current = 1; |
| 1206 |
} |
} |
| 1207 |
else // something strange |
else // something strange |
| 1208 |
{ |
{ |
| 1209 |
log_debug("iconv(in_bytes=%ld, out_bytes=%ld) error: %d, in_buf[0]=%d\n", |
log_debug("iconv(in_bytes=%zu, out_bytes=%zu) error: %d, in_buf[0]=%d\n", |
| 1210 |
in_bytes, out_bytes, errno, in_buf[0]); |
in_bytes, out_bytes, errno, (unsigned char)in_buf[0]); |
| 1211 |
*p_buf_offset = (int)(in_buf - p_buf); |
*p_buf_offset = (int)(in_buf - p_buf); |
| 1212 |
*p_conv_len = (int)(conv_size - out_bytes); |
*p_conv_len = (int)(conv_size - out_bytes); |
| 1213 |
skip_current = 1; |
skip_current = 1; |