Compiler warning fixes and improved error handling.

Fixes multiple:
  warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
  warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]

Improves some error messages.
This commit is contained in:
Chris Caputo
2020-03-08 22:57:45 +00:00
parent d8fbae0643
commit b71aa3f21d

View File

@@ -914,7 +914,7 @@ bgpq_expand(struct bgpq_expander* b)
SX_DEBUG(debug_expander, "Sending '!!' to server to request for the" SX_DEBUG(debug_expander, "Sending '!!' to server to request for the"
"connection to remain open\n"); "connection to remain open\n");
if ((ret = write(fd, "!!\n", 3)) != 3) { if ((ret = write(fd, "!!\n", 3)) != 3) {
sx_report(SX_ERROR,"Partial write to IRRd: %i bytes, %s\n", sx_report(SX_ERROR, "Partial write of multiple command mode to IRRd: %i bytes, %s\n",
ret, strerror(errno)); ret, strerror(errno));
exit(1); exit(1);
} }
@@ -923,9 +923,24 @@ bgpq_expand(struct bgpq_expander* b)
SX_DEBUG(debug_expander, "b->identify: Sending '!n " SX_DEBUG(debug_expander, "b->identify: Sending '!n "
PACKAGE_STRING "' to server.\n"); PACKAGE_STRING "' to server.\n");
char ident[128]; char ident[128];
snprintf(ident, sizeof(ident), "!n" PACKAGE_STRING "\n"); int ilen = snprintf(ident, sizeof(ident), "!n" PACKAGE_STRING "\n");
write(fd, ident, strlen(ident)); if (ilen > 0) {
read(fd, ident, sizeof(ident)); if ((ret = write(fd, ident, ilen)) != ilen) {
sx_report(SX_ERROR, "Partial write of identifier to IRRd: %i bytes, %s\n",
ret, strerror(errno));
exit(1);
}
memset(ident, 0, sizeof(ident));
if (0 < read(fd, ident, sizeof(ident))) {
SX_DEBUG(debug_expander, "Got answer %s", ident);
} else {
sx_report(SX_ERROR, "ident - failed read from IRRd\n");
exit(1);
}
} else {
sx_report(SX_ERROR, "snprintf(ident) failed\n");
exit(1);
}
} }
/* Test whether the server has support for the A query */ /* Test whether the server has support for the A query */
@@ -933,32 +948,54 @@ bgpq_expand(struct bgpq_expander* b)
char aret[128]; char aret[128];
char aresp[] = "F Missing required set name for A query"; char aresp[] = "F Missing required set name for A query";
SX_DEBUG(debug_expander, "Testing support for A queries\n"); SX_DEBUG(debug_expander, "Testing support for A queries\n");
write(fd, "!a\n", 3); if ((ret = write(fd, "!a\n", 3)) != 3) {
sx_report(SX_ERROR, "Partial write of '!a' test query to IRRd: %i bytes, %s\n",
ret, strerror(errno));
exit(1);
}
memset(aret, 0, sizeof(aret)); memset(aret, 0, sizeof(aret));
read(fd, aret, sizeof(aret)); if (0 < read(fd, aret, sizeof(aret))) {
if (strncmp(aret, aresp, strlen(aresp)) == 0) { if (strncmp(aret, aresp, strlen(aresp)) == 0) {
SX_DEBUG(debug_expander, "Server supports A query\n"); SX_DEBUG(debug_expander, "Server supports A query\n");
aquery = 1; aquery = 1;
} else } else {
SX_DEBUG(debug_expander, "No support for A queries\n"); SX_DEBUG(debug_expander, "No support for A queries\n");
} }
} else {
sx_report(SX_ERROR, "'!a' query test - failed read from IRRd\n");
exit(1);
}
}
if (b->sources && b->sources[0] != 0) { if (b->sources && b->sources[0] != 0) {
int slen = strlen(b->sources) + 4; int slen = strlen(b->sources) + 4;
if (slen < 128) if (slen < 128)
slen = 128; slen = 128;
char sources[slen]; char sources[slen];
snprintf(sources, sizeof(sources), "!s%s\n", b->sources); slen = snprintf(sources, sizeof(sources), "!s%s\n", b->sources);
if (slen > 0) {
SX_DEBUG(debug_expander, "Requesting sources %s", sources); SX_DEBUG(debug_expander, "Requesting sources %s", sources);
write(fd, sources, strlen(sources)); if ((ret = write(fd, sources, slen)) != slen) {
memset(sources, 0, slen); sx_report(SX_ERROR, "Partial write of sources to IRRd: %i bytes, %s\n",
read(fd, sources, slen); ret, strerror(errno));
SX_DEBUG(debug_expander,"Got answer %s", sources); exit(1);
}
memset(sources, 0, sizeof(sources));
if (0 < read(fd, sources, sizeof(sources))) {
SX_DEBUG(debug_expander, "Got answer %s", sources);
if (sources[0] != 'C') { if (sources[0] != 'C') {
sx_report(SX_ERROR, "Invalid source(s) '%s': %s\n", sx_report(SX_ERROR, "Invalid source(s) '%s': %s\n",
b->sources, sources); b->sources, sources);
exit(1); exit(1);
} }
} else {
sx_report(SX_ERROR, "sources - failed read from IRRd\n");
exit(1);
}
} else {
sx_report(SX_ERROR, "snprintf(sources) failed\n");
exit(1);
}
} }
if (pipelining) if (pipelining)
@@ -1037,7 +1074,11 @@ bgpq_expand(struct bgpq_expander* b)
} }
} }
write(fd, "!q\n",3); if ((ret = write(fd, "!q\n", 3)) != 3) {
sx_report(SX_ERROR, "Partial write of quit to IRRd: %i bytes, %s\n",
ret, strerror(errno));
// not worth exiting due to this
}
if (pipelining) { if (pipelining) {
int fl = fcntl(fd, F_GETFL); int fl = fcntl(fd, F_GETFL);
fl &= ~O_NONBLOCK; fl &= ~O_NONBLOCK;