From 8d5dc71d64e91d0ed85730e3c2a5b9ea494dc25c Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 15 May 2012 11:11:35 -0700 Subject: uhd: used shared get_tmp_path for logging as well Moved some of the log.cpp tmp paths smarts into paths as well --- host/lib/utils/log.cpp | 47 +++-------------------------------------------- host/lib/utils/paths.cpp | 30 ++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 46 deletions(-) (limited to 'host/lib/utils') diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index 31d11796e..d6d1786c7 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -1,5 +1,5 @@ // -// Copyright 2011 Ettus Research LLC +// Copyright 2012 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -35,12 +36,6 @@ namespace boost{ namespace interprocess{ #else #include #endif -#ifdef BOOST_MSVC -#define USE_GET_TEMP_PATH -#include //GetTempPath -#endif -#include //P_tmpdir -#include //getenv #include #include #include @@ -49,42 +44,6 @@ namespace fs = boost::filesystem; namespace pt = boost::posix_time; namespace ip = boost::interprocess; -/*********************************************************************** - * Helper function to get the system's temporary path - **********************************************************************/ -static fs::path get_temp_path(void){ - const char *tmp_path = NULL; - - //try the official uhd temp path environment variable - tmp_path = std::getenv("UHD_TEMP_PATH"); - if (tmp_path != NULL) return tmp_path; - - //try the windows function if available - #ifdef USE_GET_TEMP_PATH - char lpBuffer[2048]; - if (GetTempPath(sizeof(lpBuffer), lpBuffer)) return lpBuffer; - #endif - - //try windows environment variables - tmp_path = std::getenv("TMP"); - if (tmp_path != NULL) return tmp_path; - - tmp_path = std::getenv("TEMP"); - if (tmp_path != NULL) return tmp_path; - - //try the stdio define if available - #ifdef P_tmpdir - return P_tmpdir; - #endif - - //try unix environment variables - tmp_path = std::getenv("TMPDIR"); - if (tmp_path != NULL) return tmp_path; - - //give up and use the unix default - return "/tmp"; -} - /*********************************************************************** * Global resources for the logger **********************************************************************/ @@ -119,7 +78,7 @@ public: void log_to_file(const std::string &log_msg){ boost::mutex::scoped_lock lock(_mutex); if (_file_lock == NULL){ - const std::string log_path = (get_temp_path() / "uhd.log").string(); + const std::string log_path = (fs::path(uhd::get_tmp_path()) / "uhd.log").string(); _file_stream.open(log_path.c_str(), std::fstream::out | std::fstream::app); _file_lock = new ip::file_lock(log_path.c_str()); } diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 4fc877d5d..43094521a 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010-2011 Ettus Research LLC +// Copyright 2010-2012 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -26,6 +26,10 @@ #include #include //getenv #include //P_tmpdir +#ifdef BOOST_MSVC +#define USE_GET_TEMP_PATH +#include //GetTempPath +#endif namespace fs = boost::filesystem; @@ -87,13 +91,35 @@ std::vector get_module_paths(void){ * Implement the functions in paths.hpp **********************************************************************/ std::string uhd::get_tmp_path(void){ - const char *tmp_path = std::getenv("TMP"); + const char *tmp_path = NULL; + + //try the official uhd temp path environment variable + tmp_path = std::getenv("UHD_TEMP_PATH"); + if (tmp_path != NULL) return tmp_path; + + //try the windows function if available + #ifdef USE_GET_TEMP_PATH + char lpBuffer[2048]; + if (GetTempPath(sizeof(lpBuffer), lpBuffer)) return lpBuffer; + #endif + + //try windows environment variables + tmp_path = std::getenv("TMP"); if (tmp_path != NULL) return tmp_path; + tmp_path = std::getenv("TEMP"); + if (tmp_path != NULL) return tmp_path; + + //try the stdio define if available #ifdef P_tmpdir if (P_tmpdir != NULL) return P_tmpdir; #endif + //try unix environment variables + tmp_path = std::getenv("TMPDIR"); + if (tmp_path != NULL) return tmp_path; + + //give up and use the unix default return "/tmp"; } -- cgit v1.2.3