Commit 1a8d0371 authored by Steven Murray's avatar Steven Murray
Browse files

I have made m_foreground and m_commandLineHasBeenParsed private member variables

of the following class:

    castor::server::Daemon

Subclasses now have a more explicit API for parsing the command-line.  They
can delegate the task to the above Daemon class or they can implement there own
parsing logic.  In the latter case the subclass must call the following
Daemon method:

    castor::server::Daemon::setCommandLineParsed(bool foreground);

This method makes it clear what the Daemon class needs to know from a parse of
the command-line.  If a client subclass calls the getForeground() method of the
Daemon class before callng setCommandLineParsed() then a CommandLineNotParsed
exception shall be raised.
parent a594dd27
......@@ -174,6 +174,7 @@ void castor::rh::Server::help(std::string programName)
//------------------------------------------------------------------------------
void castor::rh::Server::parseCommandLine(int argc, char *argv[]) throw (castor::exception::Exception)
{
bool foreground = false; // Should the daemon run in the foreground?
Coptions_t longopts[] =
{
{"foreground", NO_ARGUMENT, NULL, 'f'},
......@@ -197,7 +198,7 @@ void castor::rh::Server::parseCommandLine(int argc, char *argv[]) throw (castor:
while ((c = Cgetopt_long(argc, argv, "fsR:p:c:nmh", longopts, NULL)) != -1) {
switch (c) {
case 'f':
m_foreground = true;
foreground = true;
break;
case 'c':
{
......@@ -294,7 +295,8 @@ void castor::rh::Server::parseCommandLine(int argc, char *argv[]) throw (castor:
mc->addHistogram(new castor::metrics::Histogram(
"Users", &castor::rh::UserCounter::instantiate));
*/
}
}
setCommandLineHasBeenParsed(foreground);
}
//------------------------------------------------------------------------------
......
......@@ -35,10 +35,10 @@
//------------------------------------------------------------------------------
castor::server::Daemon::Daemon(std::ostream &stdOut, std::ostream &stdErr,
log::Logger &logger) throw():
m_foreground(false),
m_commandLineHasBeenParsed(false),
m_stdOut(stdOut),
m_stdErr(stdErr),
m_foreground(false),
m_commandLineHasBeenParsed(false),
m_runAsStagerSuperuser(false),
m_logger(logger) {
}
......@@ -146,6 +146,15 @@ bool castor::server::Daemon::getForeground() const
return m_foreground;
}
//-----------------------------------------------------------------------------
// setCommandLineParsed
//-----------------------------------------------------------------------------
void castor::server::Daemon::setCommandLineHasBeenParsed(const bool foreground)
throw() {
m_foreground = foreground;
m_commandLineHasBeenParsed = true;
}
//-----------------------------------------------------------------------------
// dlfInit
//-----------------------------------------------------------------------------
......
......@@ -91,6 +91,16 @@ public:
protected:
/**
* Tells the daemon object that the command-line has been parsed. This
* method allows subclasses to implement their own command-line parsing logic,
* whilst enforcing the fact that they must provide values for the options and
* arguments this class requires.
*
* @param foreground Set to true if the daemon should run in the foreground.
*/
void setCommandLineHasBeenParsed(const bool foreground) throw();
/**
* Initializes the DLF, both for streaming and regular messages
* Does not create the DLF thread, this is created after daemonization
......@@ -221,27 +231,27 @@ protected:
const std::string &msg) throw();
/**
* Flag indicating whether the server should run in foreground or background
* mode.
* Stream representing standard out.
*/
bool m_foreground;
std::ostream &m_stdOut;
/**
* True if the command-line has been parsed.
* Stream representing standard in.
*/
bool m_commandLineHasBeenParsed;
std::ostream &m_stdErr;
private:
/**
* Stream representing standard out.
* Flag indicating whether the server should run in foreground or background
* mode.
*/
std::ostream &m_stdOut;
bool m_foreground;
/**
* Stream reprsenting standard in.
* True if the command-line has been parsed.
*/
std::ostream &m_stdErr;
private:
bool m_commandLineHasBeenParsed;
/**
* Flag indicating whether the server should
......
......@@ -48,6 +48,7 @@ castor::server::MultiThreadedDaemon::~MultiThreadedDaemon() throw() {
//------------------------------------------------------------------------------
void castor::server::MultiThreadedDaemon::parseCommandLine(int argc,
char *argv[]) throw(castor::exception::Exception) {
bool foreground = false; // Should the daemon run in the foreground?
Coptions_t* longopts = new Coptions_t[m_threadPools.size() + 5];
char tparam[] = "Xthreads";
......@@ -88,7 +89,7 @@ void castor::server::MultiThreadedDaemon::parseCommandLine(int argc,
longopts, NULL)) != -1) {
switch (c) {
case 'f':
m_foreground = true;
foreground = true;
break;
case 'c':
setenv("PATH_CONFIG", Coptarg, 1);
......@@ -117,7 +118,7 @@ void castor::server::MultiThreadedDaemon::parseCommandLine(int argc,
};
delete[] longopts;
m_commandLineHasBeenParsed = true;
setCommandLineHasBeenParsed(foreground);
}
//------------------------------------------------------------------------------
......@@ -156,7 +157,7 @@ void castor::server::MultiThreadedDaemon::addThreadPool(
//------------------------------------------------------------------------------
void castor::server::MultiThreadedDaemon::start()
throw(castor::exception::Exception) {
if (m_foreground) {
if (getForeground()) {
m_stdOut << "Starting " << getServerName() << std::endl;
}
......@@ -202,7 +203,7 @@ void castor::server::MultiThreadedDaemon::setupMultiThreadedSignalHandling()
// Mask all signals so that user threads are not unpredictably
// interrupted by them
sigemptyset(&m_signalSet);
if(m_foreground) {
if(getForeground()) {
// In foreground we catch Ctrl-C as well; we don't want to catch
// it in background to ease debugging with gdb, as gdb has its own
// SIGINT handler to pause the process anywhere. Our signal handler
......
......@@ -125,7 +125,7 @@ int castor::tape::tapebridge::TapeBridgeDaemon::exceptionThrowingMain(
}
// Pass the foreground option to the super class BaseDaemon
m_foreground = m_parsedCommandLine.foregroundOptionSet;
setCommandLineHasBeenParsed(m_parsedCommandLine.foregroundOptionSet);
// Determine and log the configuration parameters used by the tapebridged
// daemon to know how many files should be bulk requested per request for
......
......@@ -97,7 +97,7 @@ void castor::tape::Server::Daemon::run() {
/* Block signals, we will handle them synchronously */
blockSignals();
/* Daemonize if requested */
if (!m_foreground) daemonize();
if (!getForeground()) daemonize();
/* Setup the the mother forker, which will spawn and handle the tape sessions */
/* TODO */
/* Setup the listening socket for VDQM requests */
......@@ -108,9 +108,9 @@ void castor::tape::Server::Daemon::run() {
//------------------------------------------------------------------------------
// parseCommandLineOptions
//------------------------------------------------------------------------------
void castor::tape::Server::Daemon::parseCommandLineOptions(int argc, char** argv)
throw (castor::tape::Exception)
{
void castor::tape::Server::Daemon::parseCommandLineOptions(int argc,
char** argv) throw (castor::tape::Exception) {
bool foreground = false; // Should the daemon run in the foreground?
/* Expect -f or --foreground */
struct ::option opts[] = {
{ "foreground", no_argument, 0, 'f'},
......@@ -120,7 +120,7 @@ throw (castor::tape::Exception)
while (-1 != (c = getopt_long(argc, argv, ":f", opts, NULL))) {
switch (c) {
case 'f':
m_foreground = true;
foreground = true;
break;
case ':':
{
......@@ -144,6 +144,7 @@ throw (castor::tape::Exception)
}
}
}
setCommandLineHasBeenParsed(foreground);
}
//------------------------------------------------------------------------------
......
......@@ -90,8 +90,9 @@ void castor::vdqm::VdqmServer::logStart(Cuuid_t &cuuid, const int argc,
//------------------------------------------------------------------------------
// parseCommandLine
//------------------------------------------------------------------------------
void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) throw() {
void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv)
throw() {
bool foreground = false; // Should the daemon run in the foreground?
static struct Coptions longopts[] = {
{"foreground" , NO_ARGUMENT , NULL, 'f'},
{"config" , REQUIRED_ARGUMENT, NULL, 'c'},
......@@ -109,7 +110,7 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
while((c=Cgetopt_long(argc, argv, "fc:hr:j:s:", longopts, NULL)) != -1) {
switch (c) {
case 'f':
m_foreground = true;
foreground = true;
break;
case 'c':
{
......@@ -129,7 +130,7 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
VDQM_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage();
exit(1);
......@@ -161,7 +162,7 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
VDQM_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage();
exit(1);
......@@ -178,7 +179,7 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
VDQM_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage();
exit(1);
......@@ -196,7 +197,7 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
VDQM_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage();
exit(1);
......@@ -215,7 +216,7 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
VDQM_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage();
exit(1);
......@@ -235,11 +236,13 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
VDQM_FAILED_TO_PARSE_COMMAND_LINE, 1, params);
// Print error and usage to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
usage();
exit(1);
}
setCommandLineHasBeenParsed(foreground);
}
......@@ -248,7 +251,7 @@ void castor::vdqm::VdqmServer::parseCommandLine(const int argc, char **argv) thr
//------------------------------------------------------------------------------
void castor::vdqm::VdqmServer::usage()
throw() {
std::cerr << "Usage: vdqmd [options]\n"
m_stdErr << "Usage: vdqmd [options]\n"
"\n"
"where options can be:\n"
"\n"
......@@ -289,7 +292,7 @@ void castor::vdqm::VdqmServer::initDatabaseService(Cuuid_t &cuuid) {
VDQM_FAILED_TO_INIT_DB_SERVICE, 1, params);
// Print error to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
exit(1);
}
......@@ -310,7 +313,7 @@ void castor::vdqm::VdqmServer::initDatabaseService(Cuuid_t &cuuid) {
VDQM_FAILED_TO_INIT_DB_SERVICE, 1, params);
// Print error to stderr and then abort
std::cerr << std::endl << "Error: " << oss.str()
m_stdErr << std::endl << "Error: " << oss.str()
<< std::endl << std::endl;
exit(1);
}
......
Supports Markdown
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