error handling enhancements

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2020-08-15 13:05:49 +02:00
parent 9ab656dbe2
commit 84448d5e4e
3 changed files with 5 additions and 5 deletions

View File

@@ -112,6 +112,7 @@ int main(void)
{ {
fprintf(stderr, "JSON parsing failed with return value %d at position %u\n", r, parser.pos); fprintf(stderr, "JSON parsing failed with return value %d at position %u\n", r, parser.pos);
fprintf(stderr, "JSON string: '%.*s'\n", (int)(json_bytes - json_start), (char *)(buf + json_start)); fprintf(stderr, "JSON string: '%.*s'\n", (int)(json_bytes - json_start), (char *)(buf + json_start));
exit(1);
} }
for (int i = 1; i < r; i++) for (int i = 1; i < r; i++)

View File

@@ -729,7 +729,7 @@ static void send_to_json_sink(struct nDPId_reader_thread * const reader_thread,
} }
errno = 0; errno = 0;
if (reader_thread->json_sock_reconnect == 0 && write(reader_thread->json_sockfd, newline_json_str, s_ret) <= 0) if (reader_thread->json_sock_reconnect == 0 && write(reader_thread->json_sockfd, newline_json_str, s_ret) != s_ret)
{ {
saved_errno = errno; saved_errno = errno;
syslog(LOG_DAEMON | LOG_ERR, syslog(LOG_DAEMON | LOG_ERR,

View File

@@ -166,7 +166,8 @@ static void disconnect_client(int epollfd, struct remote_desc * const current)
{ {
if (epoll_ctl(epollfd, EPOLL_CTL_DEL, current->fd, NULL) < 0) if (epoll_ctl(epollfd, EPOLL_CTL_DEL, current->fd, NULL) < 0)
{ {
syslog(LOG_DAEMON | LOG_ERR, "Error deleting fd from epollq: %s", strerror(errno)); syslog(LOG_DAEMON | LOG_ERR, "Error deleting fd %d from epollq %d: %s",
current->fd, epollfd, strerror(errno));
} }
if (close(current->fd) != 0) if (close(current->fd) != 0)
{ {
@@ -446,9 +447,7 @@ int main(int argc, char ** argv)
} }
if (bytes_read == 0) if (bytes_read == 0)
{ {
syslog(LOG_DAEMON, syslog(LOG_DAEMON, "collector connection closed during read");
"%s connection closed during read",
(current->type == JSON_SOCK ? "collector" : "distributor"));
disconnect_client(epollfd, current); disconnect_client(epollfd, current);
continue; continue;
} }