Commit aef01265 authored by Steven Murray's avatar Steven Murray
Browse files

Explicitly set the names of tapeserverd child-processes

The names of the tapeserverd child processes are now as follows:

tpforker   - The process forker
tpcleaner  - A cleaner session
tplabel    - A label session
tptransfer - A data tranfer session
parent 565896e3
......@@ -60,11 +60,13 @@ castor::tape::tapeserver::daemon::ProcessForker::ProcessForker(
log::Logger &log,
const int cmdSocket,
const int reaperSocket,
const std::string &hostName) throw():
const std::string &hostName,
char *const argv0) throw():
m_log(log),
m_cmdSocket(cmdSocket),
m_reaperSocket(reaperSocket),
m_hostName(hostName) {
m_hostName(hostName),
m_argv0(argv0) {
}
//------------------------------------------------------------------------------
......@@ -122,13 +124,8 @@ bool castor::tape::tapeserver::daemon::ProcessForker::handleEvents() throw() {
}
// If program execution reached here then an exception was thrown
// Sleep for a second in order to prevent a tight loop in the case of the
// perpetual raising of exceptions
sleep(1);
// An exception should not stop the main event loop
return true; // The main event loop should continue
m_log(LOG_ERR, "ProcessForker is gracefully shutting down");
return false;
}
//------------------------------------------------------------------------------
......@@ -194,15 +191,9 @@ bool castor::tape::tapeserver::daemon::ProcessForker::handleMsg() {
const int timeout = 10; // Timeout in seconds
frame = ProcessForkerUtils::readFrame(m_cmdSocket, timeout);
} catch(castor::exception::Exception &ne) {
log::Param params[] = {log::Param("message", ne.getMessage().str())};
m_log(LOG_ERR, "Failed to handle message", params);
sleep(1); // Sleep a moment to avoid going into a tight error loop
return true; // The main event loop should continue
/*
castor::exception::Exception ex;
ex.getMessage() << "Failed to handle message: " << ne.getMessage().str();
throw ex;
*/
}
log::Param params[] = {
......@@ -308,15 +299,14 @@ castor::tape::tapeserver::daemon::ProcessForker::MsgHandlerResult
log::Param params[] = {log::Param("pid", forkRc)};
m_log(LOG_INFO, "ProcessForker forked cleaner session", params);
// TO BE DONE
waitpid(forkRc, NULL, 0);
return createForkSucceededResult(forkRc, true);
// Else this is the child process
} else {
closeCmdReceiverSocket();
castor::utils::setProcessNameAndCmdLine(m_argv0, "tpcleaner");
try {
exit(runCleanerSession(rqst));
} catch(castor::exception::Exception &ne) {
......@@ -369,6 +359,8 @@ castor::tape::tapeserver::daemon::ProcessForker::MsgHandlerResult
} else {
closeCmdReceiverSocket();
castor::utils::setProcessNameAndCmdLine(m_argv0, "tptransfer");
try {
exit(runDataTransferSession(rqst));
} catch(castor::exception::Exception &ne) {
......@@ -422,6 +414,8 @@ castor::tape::tapeserver::daemon::ProcessForker::MsgHandlerResult
} else {
closeCmdReceiverSocket();
castor::utils::setProcessNameAndCmdLine(m_argv0, "tplabel");
try {
exit(runLabelSession(rqst));
} catch(castor::exception::Exception &ne) {
......
......@@ -58,9 +58,10 @@ public:
* ProcessForker.
* @param hostName The name of the host on which the tapeserverd daemon is
* running.
* @param argv0 Pointer to argv[0], the command-line.
*/
ProcessForker(log::Logger &log, const int cmdSocket, const int reaperSocket,
const std::string &hostName) throw();
const std::string &hostName, char *const argv0) throw();
/**
* Destructor.
......@@ -105,6 +106,11 @@ private:
*/
const std::string m_hostName;
/**
* Pointer to argv[0], the command-line.
*/
char *const m_argv0;
/**
* Idempotent method that closes the socket used for receving commands
* from the ProcessForker proxy.
......
......@@ -59,10 +59,11 @@ TEST_F(castor_tape_tapeserver_daemon_ProcessForkerTest, constructor) {
const std::string programName = "unittests";
const std::string hostName = "hostName";
castor::log::DummyLogger log(programName);
char argv0[12] = "tapeserverd";
std::auto_ptr<ProcessForker> processForker;
ASSERT_NO_THROW(processForker.reset(
new ProcessForker(log, cmdReceiverSocket.get(), reaperSenderSocket.get(),
hostName)));
hostName, argv0)));
cmdReceiverSocket.release();
}
......@@ -82,10 +83,11 @@ TEST_F(castor_tape_tapeserver_daemon_ProcessForkerTest, socketproxy) {
const std::string programName = "unittests";
const std::string hostName = "hostName";
castor::log::DummyLogger log(programName);
char argv0[12] = "tapeserverd";
std::auto_ptr<ProcessForker> processForker;
ASSERT_NO_THROW(processForker.reset(
new ProcessForker(log, cmdReceiverSocket.get(), reaperSenderSocket.get(),
hostName)));
hostName, argv0)));
cmdReceiverSocket.release();
std::auto_ptr<ProcessForkerProxySocket> processForkerProxy;
......
......@@ -311,6 +311,8 @@ pid_t castor::tape::tapeserver::daemon::TapeDaemon::forkProcessForker(
closeTapeDaemonSideOfCmdPair(cmdPair);
closeTapeDaemonSideOfReaperPair(reaperPair);
castor::utils::setProcessNameAndCmdLine(m_argv[0], "tpforker");
exit(runProcessForker(cmdPair.processForker, reaperPair.processForker));
}
}
......@@ -511,7 +513,7 @@ int castor::tape::tapeserver::daemon::TapeDaemon::runProcessForker(
const int cmdReceiverSocket, const int reaperSenderSocket) throw() {
try {
ProcessForker processForker(m_log, cmdReceiverSocket, reaperSenderSocket,
m_hostName);
m_hostName, m_argv[0]);
processForker.execute();
return 0;
} catch(castor::exception::Exception &ex) {
......
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