diff options
author | Alan Conway <aconway@apache.org> | 2008-02-06 22:49:10 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-02-06 22:49:10 +0000 |
commit | 52faea872170225ac1a5441202ad7f35f88c3c77 (patch) | |
tree | 29a46e1acd2436124da3e574209f3ef6f726ed0b /cpp/src | |
parent | 16b2214415090d952d6b8f57a34b03162e9e27b1 (diff) | |
download | qpid-python-52faea872170225ac1a5441202ad7f35f88c3c77.tar.gz |
From Ted Ross, https://issues.apache.org/jira/browse/QPID-780
Implementation of --data-dir for qpidd.
Additions by myself:
- set QPID_DATA_DIR= in test env so existing tests can run with no data dir.
- src/Makefile.am and qpidc.spec.in install /var/lib/qpidd directory.
NOTE: qpidd with no optoins will now FAIL if it cannot write /var/lib/qpidd.
Start it with --data-dir= or set QPID_DATA_DIR= in your environement to
run with no data directory.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@619200 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Makefile.am | 6 | ||||
-rw-r--r-- | cpp/src/qpid/DataDir.cpp | 69 | ||||
-rw-r--r-- | cpp/src/qpid/DataDir.h | 47 | ||||
-rw-r--r-- | cpp/src/qpid/broker/Broker.cpp | 6 | ||||
-rw-r--r-- | cpp/src/qpid/broker/Broker.h | 6 | ||||
-rw-r--r-- | cpp/src/tests/BrokerFixture.h | 1 | ||||
-rw-r--r-- | cpp/src/tests/Makefile.am | 2 |
7 files changed, 134 insertions, 3 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 57a0761935..d2242c2695 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -140,6 +140,7 @@ libqpidcommon_la_SOURCES = \ qpid/sys/SystemInfo.cpp \ qpid/sys/Serializer.cpp \ qpid/sys/Shlib.cpp \ + qpid/DataDir.cpp \ qpid/Options.cpp \ qpid/log/Options.cpp \ qpid/log/Selector.cpp \ @@ -236,6 +237,7 @@ libqpidclient_la_SOURCES = \ nobase_include_HEADERS = \ $(platform_hdr) \ qpid/assert.h \ + qpid/DataDir.h \ qpid/Exception.h \ qpid/Msg.h \ qpid/Options.h \ @@ -438,3 +440,7 @@ nobase_include_HEADERS = \ dist-hook: $(BUILT_SOURCES) $(MAKE) qpidd +# Create the default data directory +install-data-local: + $(mkinstalldirs) $(DESTDIR)/$(localstatedir)/lib/qpidd + diff --git a/cpp/src/qpid/DataDir.cpp b/cpp/src/qpid/DataDir.cpp new file mode 100644 index 0000000000..baf536c109 --- /dev/null +++ b/cpp/src/qpid/DataDir.cpp @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "Exception.h" +#include "DataDir.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <cerrno> + +namespace qpid { + +DataDir::DataDir (std::string path) : + enabled (!path.empty ()), + dirPath (path) +{ + if (!enabled) + return; + + const char *cpath = dirPath.c_str (); + struct stat s; + + if (::stat (cpath, &s)) + throw Exception ("Data directory not found: " + path); + + std::string lockFile (path); + lockFile = lockFile + "/lock"; + int fd = ::open (lockFile.c_str (), O_CREAT | O_EXCL, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd == -1) + { + if (errno == EEXIST) + throw Exception ("Data directory is locked by another process"); + if (errno == EACCES) + throw Exception ("Insufficient privileges for data directory"); + + std::ostringstream oss; + oss << "Error locking data directory: errno=" << errno; + throw Exception (oss.str ()); + } +} + +DataDir::~DataDir () +{ + std::string lockFile (dirPath); + lockFile = lockFile + "/lock"; + + ::unlink (lockFile.c_str ()); +} + +} // namespace qpid + diff --git a/cpp/src/qpid/DataDir.h b/cpp/src/qpid/DataDir.h new file mode 100644 index 0000000000..56aa4f26d7 --- /dev/null +++ b/cpp/src/qpid/DataDir.h @@ -0,0 +1,47 @@ +#ifndef QPID_DATADIR_H +#define QPID_DATADIR_H + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include <string> + +namespace qpid { + +/** + * DataDir class. + */ +class DataDir +{ + const bool enabled; + const std::string dirPath; + + public: + + DataDir (std::string path); + ~DataDir (); + + bool isEnabled () { return enabled; } + std::string getPath () { return dirPath; } +}; + +} // namespace qpid + +#endif /*!QPID_DATADIR_H*/ diff --git a/cpp/src/qpid/broker/Broker.cpp b/cpp/src/qpid/broker/Broker.cpp index 7d30ab8ed2..57ff7a550c 100644 --- a/cpp/src/qpid/broker/Broker.cpp +++ b/cpp/src/qpid/broker/Broker.cpp @@ -60,6 +60,7 @@ namespace broker { Broker::Options::Options(const std::string& name) : qpid::Options(name), + dataDir("/var/lib/qpidd"), port(DEFAULT_PORT), workerThreads(5), maxConnections(500), @@ -72,6 +73,8 @@ Broker::Options::Options(const std::string& name) : int c = sys::SystemInfo::concurrency(); workerThreads=std::max(2,c); addOptions() + ("data-dir", optValue(dataDir,"DIR"), + "Directory to contain persistent data generated by the broker") ("port,p", optValue(port,"PORT"), "Tells the broker to listen on PORT") ("worker-threads", optValue(workerThreads, "N"), @@ -82,7 +85,7 @@ Broker::Options::Options(const std::string& name) : "Sets the connection backlog limit for the server socket") ("staging-threshold", optValue(stagingThreshold, "N"), "Stages messages over N bytes to disk") - ("mgmt,m", optValue(enableMgmt,"yes|no"), + ("mgmt-enable,m", optValue(enableMgmt,"yes|no"), "Enable Management") ("mgmt-pub-interval", optValue(mgmtPubInterval, "SECONDS"), "Management Publish Interval") @@ -100,6 +103,7 @@ const std::string qpid_management("qpid.management"); Broker::Broker(const Broker::Options& conf) : config(conf), store(0), + dataDir(conf.dataDir), factory(*this), sessionManager(conf.ack) { diff --git a/cpp/src/qpid/broker/Broker.h b/cpp/src/qpid/broker/Broker.h index a2cb3466be..852cb2da42 100644 --- a/cpp/src/qpid/broker/Broker.h +++ b/cpp/src/qpid/broker/Broker.h @@ -37,6 +37,7 @@ #include "qpid/management/ArgsBrokerConnect.h" #include "qpid/Options.h" #include "qpid/Plugin.h" +#include "qpid/DataDir.h" #include "qpid/framing/FrameHandler.h" #include "qpid/framing/OutputHandler.h" #include "qpid/framing/ProtocolInitiation.h" @@ -59,7 +60,8 @@ class Broker : public sys::Runnable, public Plugin::Target, public management::M struct Options : public qpid::Options { Options(const std::string& name="Broker Options"); - + + std::string dataDir; uint16_t port; int workerThreads; int maxConnections; @@ -99,6 +101,7 @@ class Broker : public sys::Runnable, public Plugin::Target, public management::M ExchangeRegistry& getExchanges() { return exchanges; } uint64_t getStagingThreshold() { return config.stagingThreshold; } DtxManager& getDtxManager() { return dtxManager; } + DataDir& getDataDir() { return dataDir; } SessionManager& getSessionManager() { return sessionManager; } @@ -113,6 +116,7 @@ class Broker : public sys::Runnable, public Plugin::Target, public management::M Options config; sys::Acceptor::shared_ptr acceptor; MessageStore* store; + DataDir dataDir; QueueRegistry queues; ExchangeRegistry exchanges; diff --git a/cpp/src/tests/BrokerFixture.h b/cpp/src/tests/BrokerFixture.h index 1a397c76c8..b4e4a2082b 100644 --- a/cpp/src/tests/BrokerFixture.h +++ b/cpp/src/tests/BrokerFixture.h @@ -46,6 +46,7 @@ struct BrokerFixture { // Management doesn't play well with multiple in-process brokers. opts.enableMgmt=false; opts.workerThreads=1; + opts.dataDir=""; broker = Broker::create(opts); // TODO aconway 2007-12-05: At one point BrokerFixture // tests could hang in Connection ctor if the following diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 3d152258a3..5d29f3d979 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -109,7 +109,7 @@ testprogs= \ check_PROGRAMS += $(testprogs) interop_runner -TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) $(srcdir)/run_test +TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) QPID_DATA_DIR= $(srcdir)/run_test system_tests = client_test quick_perftest quick_topictest TESTS += run-unit-tests start_broker $(system_tests) python_tests stop_broker |