Commit a955dee5 authored by Shawn Routhier's avatar Shawn Routhier
Browse files

Merge branch 'trac4001' Update code to clear errno before use.

Update the code to clear the errno variable before making calls that
might use it.  This should limit problems with one section of code
creating an inappropriate error message due to looking at an errno
set by some other section ofcode.
parents ed569285 ef36ce10
......@@ -74,6 +74,7 @@ extern "C" {
int load(LibraryHandle&) {
// non-zero indicates an error.
int ret_val = 0;
try {
// Instantiate the registry.
user_registry.reset(new UserRegistry());
......@@ -87,6 +88,9 @@ int load(LibraryHandle&) {
// Do an initial load of the registry.
user_registry->refresh();
// zero out the errno to be safe
errno = 0;
// Open up the output file for user_chk results.
user_chk_output.open(user_chk_output_fname,
std::fstream::out | std::fstream::app);
......
......@@ -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;
......
......@@ -815,6 +815,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);
......@@ -932,6 +936,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) {
......@@ -1039,6 +1046,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