Skip to content

Commit

Permalink
stats: fixed issues reported by coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
havraji6 committed Dec 21, 2021
1 parent e29b0f2 commit 754addb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion ipfixprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ void serve_stat_clients(ipxp_conf_t &conf, struct pollfd pfds[2])
int fd = accept(pfds[0].fd, NULL, NULL);
if (pfds[1].fd == -1) {
pfds[1].fd = fd;
} else {
} else if (fd != -1) {
// Close incoming connection
close(fd);
}
}
Expand Down
27 changes: 14 additions & 13 deletions ipfixprobe_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,29 @@ int main(int argc, char *argv[])
std::string path;
IpfixStatsParser parser;


signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);

try {
parser.parse(argc - 1, const_cast<const char **>(argv) + 1);
} catch (ParserError &e) {

if (parser.m_help) {
parser.usage(std::cout, 0);
goto EXIT;
}

path = DEFAULTSOCKETDIR "/ipfixprobe_" + std::to_string(parser.m_pid) + ".sock";
fd = connect_to_exporter(path.c_str());
if (fd == -1) {
error("connecting to exporter");
goto EXIT;
}
} catch (std::runtime_error &e) {
error(e.what());
status = EXIT_FAILURE;
goto EXIT;
}

if (parser.m_help) {
parser.usage(std::cout, 0);
goto EXIT;
}

path = DEFAULTSOCKETDIR "/ipfixprobe_" + std::to_string(parser.m_pid) + ".sock";
fd = connect_to_exporter(path.c_str());
if (fd == -1) {
error("connecting to exporter");
goto EXIT;
}
while (!stop) {
*(uint32_t *) buffer = MSG_MAGIC;
// Send stats data request
Expand Down
2 changes: 1 addition & 1 deletion stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int create_stats_sock(const char *path)

unlink(addr.sun_path);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd) {
if (fd != -1) {
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
perror("unable to bind socket");
close(fd);
Expand Down

0 comments on commit 754addb

Please sign in to comment.