Commit 46dda289 authored by Shawn Routhier's avatar Shawn Routhier

[trac4001] Clear errno before calling OS functions

parent ea99794c
......@@ -74,6 +74,10 @@ extern "C" {
int load(LibraryHandle&) {
// non-zero indicates an error.
int ret_val = 0;
// zero out the errno to be safe
errno = 0;
try {
// Instantiate the registry.
user_registry.reset(new UserRegistry());
......
......@@ -731,6 +731,9 @@ Element::fromJSON(const std::string& in, bool preproc) {
ElementPtr
Element::fromJSONFile(const std::string& file_name,
bool preproc) {
// zero out the errno to be safe
errno = 0;
std::ifstream infile(file_name.c_str(), std::ios::in | std::ios::binary);
if (!infile.is_open())
{
......
// Copyright (C) 2010, 2011 Internet Systems Consortium.
// Copyright (C) 2010, 2011, 2015 Internet Systems Consortium.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -311,6 +311,9 @@ moduleSpecFromFile(const std::string& file_name, const bool check)
{
std::ifstream file;
// zero out the errno to be safe
errno = 0;
file.open(file_name.c_str());
if (!file) {
std::stringstream errs;
......
......@@ -810,6 +810,10 @@ IfaceMgr::getLocalAddress(const IOAddress& remote_addr, const uint16_t port) {
// @todo: We don't specify interface in any way here. 255.255.255.255
// We can very easily end up with a socket working on a different
// interface.
// zero out the errno to be safe
errno = 0;
sock.open(asio::ip::udp::v4(), err_code);
if (err_code) {
const char* errstr = strerror(errno);
......@@ -927,6 +931,9 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
select_timeout.tv_sec = timeout_sec;
select_timeout.tv_usec = timeout_usec;
// zero out the errno to be safe
errno = 0;
int result = select(maxfd + 1, &sockets, NULL, NULL, &select_timeout);
if (result == 0) {
......@@ -1034,6 +1041,9 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
select_timeout.tv_sec = timeout_sec;
select_timeout.tv_usec = timeout_usec;
// zero out the errno to be safe
errno = 0;
int result = select(maxfd + 1, &sockets, NULL, NULL, &select_timeout);
if (result == 0) {
......
......@@ -276,6 +276,9 @@ writeHeaderFile(const string& file, const vector<string>& ns_components,
// Text to use as the sentinels.
string sentinel_text = sentinel(header_file);
// zero out the errno to be safe
errno = 0;
// Open the output file for writing
ofstream hfile(header_file.fullName().c_str());
......@@ -378,6 +381,9 @@ writeProgramFile(const string& file, const vector<string>& ns_components,
program_file.setDirectory(output_directory);
}
// zero out the errno to be safe
errno = 0;
// Open the output file for writing
ofstream ccfile(program_file.fullName().c_str());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment