summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorStephen D. Huston <shuston@apache.org>2009-07-13 21:27:14 +0000
committerStephen D. Huston <shuston@apache.org>2009-07-13 21:27:14 +0000
commit815d45a2129244b0061bc8d59793c49f26df9f22 (patch)
tree522ec0afc081180fb45c5d6f1860d7b1c77921d1 /cpp/src
parent5254145321df2be18fce790365d203b7342f48f5 (diff)
downloadqpid-python-815d45a2129244b0061bc8d59793c49f26df9f22.tar.gz
Replace getenv usage with more secure Windows calls - silences compile diagnostics. This involved adding a new method Broker::Options::getHome() implemented separately for Windows and posix BrokerDefaults.cpp
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@793716 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/broker/Broker.cpp5
-rw-r--r--cpp/src/qpid/broker/Broker.h3
-rw-r--r--cpp/src/qpid/broker/posix/BrokerDefaults.cpp12
-rw-r--r--cpp/src/qpid/broker/windows/BrokerDefaults.cpp13
-rw-r--r--cpp/src/windows/QpiddBroker.cpp13
5 files changed, 35 insertions, 11 deletions
diff --git a/cpp/src/qpid/broker/Broker.cpp b/cpp/src/qpid/broker/Broker.cpp
index 749489fbfd..4fcb8b6451 100644
--- a/cpp/src/qpid/broker/Broker.cpp
+++ b/cpp/src/qpid/broker/Broker.cpp
@@ -57,7 +57,6 @@
#include <iostream>
#include <memory>
-#include <stdlib.h>
using qpid::sys::ProtocolFactory;
using qpid::sys::Poller;
@@ -96,9 +95,9 @@ Broker::Options::Options(const std::string& name) :
{
int c = sys::SystemInfo::concurrency();
workerThreads=c+1;
- char *home = ::getenv("HOME");
+ std::string home = getHome();
- if (home == 0)
+ if (home.length() == 0)
dataDir += DEFAULT_DATA_DIR_LOCATION;
else
dataDir += home;
diff --git a/cpp/src/qpid/broker/Broker.h b/cpp/src/qpid/broker/Broker.h
index 8f4621bb39..0a12b3f7d3 100644
--- a/cpp/src/qpid/broker/Broker.h
+++ b/cpp/src/qpid/broker/Broker.h
@@ -111,6 +111,9 @@ public:
bool requireEncrypted;
std::string knownHosts;
uint32_t maxSessionRate;
+
+ private:
+ std::string getHome();
};
private:
diff --git a/cpp/src/qpid/broker/posix/BrokerDefaults.cpp b/cpp/src/qpid/broker/posix/BrokerDefaults.cpp
index b3ef48fe58..9e463fa32d 100644
--- a/cpp/src/qpid/broker/posix/BrokerDefaults.cpp
+++ b/cpp/src/qpid/broker/posix/BrokerDefaults.cpp
@@ -20,6 +20,7 @@
*/
#include "qpid/broker/Broker.h"
+#include <stdlib.h>
namespace qpid {
namespace broker {
@@ -27,4 +28,13 @@ namespace broker {
const std::string Broker::Options::DEFAULT_DATA_DIR_LOCATION("/tmp");
const std::string Broker::Options::DEFAULT_DATA_DIR_NAME("/.qpidd");
-}}
+std::string
+Broker::Options::getHome() {
+ std::string home;
+ char *home_c = ::getenv("HOME");
+ if (home_c != 0)
+ home += home_c;
+ return home;
+}
+
+}} // namespace qpid::broker
diff --git a/cpp/src/qpid/broker/windows/BrokerDefaults.cpp b/cpp/src/qpid/broker/windows/BrokerDefaults.cpp
index 138995980a..b6862f0418 100644
--- a/cpp/src/qpid/broker/windows/BrokerDefaults.cpp
+++ b/cpp/src/qpid/broker/windows/BrokerDefaults.cpp
@@ -20,6 +20,7 @@
*/
#include "qpid/broker/Broker.h"
+#include <stdlib.h>
namespace qpid {
namespace broker {
@@ -27,4 +28,14 @@ namespace broker {
const std::string Broker::Options::DEFAULT_DATA_DIR_LOCATION("\\TEMP");
const std::string Broker::Options::DEFAULT_DATA_DIR_NAME("\\QPIDD.DATA");
-}}
+std::string
+Broker::Options::getHome() {
+ std::string home;
+ char home_c[MAX_PATH+1];
+ size_t unused;
+ if (0 == getenv_s (&unused, home_c, sizeof(home_c), "HOME"))
+ home += home_c;
+ return home;
+}
+
+}} // namespace qpid::broker
diff --git a/cpp/src/windows/QpiddBroker.cpp b/cpp/src/windows/QpiddBroker.cpp
index ed38475811..a22ccba63f 100644
--- a/cpp/src/windows/QpiddBroker.cpp
+++ b/cpp/src/windows/QpiddBroker.cpp
@@ -39,6 +39,7 @@ const char *QPIDD_MODULE_DIR = ".";
#include "qpid/broker/Broker.h"
#include <iostream>
+#include <windows.h>
using namespace qpid::broker;
@@ -145,16 +146,16 @@ struct ProcessControlOptions : public qpid::Options {
quit(false),
check(false) //, transport(TCP)
{
- char *tempDir = ::getenv("TEMP");
-
- if (tempDir == 0)
- piddir = "C:\\WINDOWS\\TEMP";
+ const DWORD pathLen = MAX_PATH + 1;
+ char tempDir[pathLen];
+ if (GetTempPath(pathLen, tempDir) == 0)
+ piddir = "C:\\WINDOWS\\TEMP\\";
else
piddir = tempDir;
- piddir += "\\qpidd";
+ piddir += "qpidd";
// Only have TCP for now, so don't need this...
- // ("transport", optValue(transport, "TRANSPORT"), "The transport for which to return the port")
+ // ("transport", optValue(transport, "TRANSPORT"), "The transport for which to return the port")
addOptions()
("pid-dir", qpid::optValue(piddir, "DIR"), "Directory where port-specific PID file is stored")
("check,c", qpid::optValue(check), "Prints the broker's process ID to stdout and returns 0 if the broker is running, otherwise returns 1")