Skip to content

Commit 8046e63

Browse files
committed
Fix(bmqbrkr): Add --prefixDir argument to override BMQ_PREFIX
Signed-off-by: Patrick M. Niedzielski <pniedzielski@bloomberg.net>
1 parent 4709e51 commit 8046e63

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/applications/bmqbrkr/bmqbrkr.m.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct TaskEnvironment {
9090
// otherwise)
9191

9292
bsl::string d_bmqPrefix;
93-
// BMQ_PREFIX directory path
93+
// Directory path to store PID, HIST, and CTL files under.
9494

9595
bsl::string d_configJson;
9696
// JSON content ouput of the generated
@@ -414,7 +414,7 @@ static int initializeTask(bsl::ostream& errorDescription,
414414
bdlf::PlaceHolders::_1, // prefix
415415
bdlf::PlaceHolders::_2)); // istream
416416

417-
// Save the PID of the process in the '${BMQ_PREFIX}/bmqbrkr.pid' file
417+
// Save the PID of the process in the '{prefix}/bmqbrkr.pid' file
418418
const bsl::string pidFile = taskEnv->d_bmqPrefix + "/bmqbrkr.pid";
419419
bsl::ofstream pidFd(pidFile.c_str());
420420
if (!pidFd) {
@@ -499,9 +499,9 @@ static void shutdownApplication(TaskEnvironment* taskEnv)
499499
app.mqba::Application::~Application();
500500
}
501501

502-
/// Update the `bmqbrkr.hist` file (in the BMQ_PREFIX directory) using the
502+
/// Update the `bmqbrkr.hist` file (in the prefix directory) using the
503503
/// specified `taskEnv`. This file contains information about the last `n`
504-
/// successfull start of the broker, in reverse time order.
504+
/// successful starts of the broker, in reverse time order.
505505
/// Each line entry has the following format:
506506
/// <currentTime_UTC>|<brokerVersion>|<configVersion>|<brokerId>
507507
///
@@ -598,6 +598,7 @@ int main(int argc, const char* argv[])
598598
{
599599
// Parse command line parameters
600600
bsl::string configDir;
601+
bsl::string prefixDir;
601602
bsl::string instanceId = "default";
602603
bsl::string hostName;
603604
bsl::string hostTags;
@@ -611,6 +612,11 @@ int main(int argc, const char* argv[])
611612
"Path to the configuration directory",
612613
balcl::TypeInfo(&configDir),
613614
balcl::OccurrenceInfo::e_REQUIRED},
615+
{"",
616+
"prefixDir",
617+
"Path to the prefix directory (where PID, HIST, and CTL files live)",
618+
balcl::TypeInfo(&prefixDir),
619+
balcl::OccurrenceInfo::e_OPTIONAL},
614620
{"i|instanceId",
615621
"instanceId",
616622
"The instance ID ('default' if not provided)",
@@ -687,8 +693,11 @@ int main(int argc, const char* argv[])
687693
TaskEnvironment taskEnv;
688694
s_taskEnv_p = &taskEnv;
689695

690-
const char* prefixEnvVar = bsl::getenv("BMQ_PREFIX");
691-
taskEnv.d_bmqPrefix = (prefixEnvVar != 0 ? prefixEnvVar : "./");
696+
// Default prefix directory to `BMQ_PREFIX` or ./
697+
if (prefixDir.empty()) {
698+
prefixDir = bsl::getenv("BMQ_PREFIX");
699+
}
700+
taskEnv.d_bmqPrefix = (!prefixDir.empty() ? prefixDir : "./");
692701
taskEnv.d_instanceId = instanceId;
693702

694703
bmqu::MemOutStream errorDescription;

src/applications/bmqbrkr/m_bmqbrkr_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class Task {
199199
// True is this object has been initialized.
200200

201201
bsl::string d_bmqPrefix;
202-
// BMQ_PREFIX directory
202+
// Directory path to store PID, HIST, and CTL files under.
203203

204204
bdlmt::EventScheduler d_scheduler;
205205
// EventScheduler

0 commit comments

Comments
 (0)