Add --nopid command line option (#1497).

Add a --nopid command line option, which causes a PID file not to be
written to the file system regardless of the presence of the <pid> tag
in the configuration file or the value of its "file" variable if it is
present.
This commit is contained in:
Chris Novakovic 2018-06-04 12:40:32 +01:00 committed by Peter Powell
parent 2772c2fa2d
commit 9cd7a2e546
2 changed files with 22 additions and 2 deletions

View File

@ -146,6 +146,18 @@ struct CommandLineConf
*/
bool writelog;
/** If this is true, a PID file will be written
* to the file given in the "file" variable of
* the <pid> tag in the config file. This is
* the default.
* Passing --nopid as a command line argument
* sets this to false; in this case, a PID file
* will not be written, even the default PID
* file that is usually written when the <pid>
* tag is not defined in the config file.
*/
bool writepid;
/** Saved argc from startup
*/
int argc;

View File

@ -186,6 +186,12 @@ bool InspIRCd::DaemonSeed()
void InspIRCd::WritePID(const std::string& filename, bool exitonfail)
{
#ifndef _WIN32
if (!ServerInstance->Config->cmdline.writepid)
{
this->Logs->Log("STARTUP", LOG_DEFAULT, "--nopid specified on command line; PID file not written.");
return;
}
std::string fname(filename);
if (fname.empty())
fname = ServerInstance->Config->Paths.PrependData("inspircd.pid");
@ -225,7 +231,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
FailedPortList pl;
// Flag variables passed to getopt_long() later
int do_version = 0, do_nofork = 0, do_debug = 0,
do_nolog = 0, do_root = 0;
do_nolog = 0, do_nopid = 0, do_root = 0;
// Initialize so that if we exit before proper initialization they're not deleted
this->Config = 0;
@ -271,6 +277,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
{ "config", required_argument, NULL, 'c' },
{ "debug", no_argument, &do_debug, 1 },
{ "nolog", no_argument, &do_nolog, 1 },
{ "nopid", no_argument, &do_nopid, 1 },
{ "runasroot", no_argument, &do_root, 1 },
{ "version", no_argument, &do_version, 1 },
#ifdef INSPIRCD_ENABLE_TESTSUITE
@ -297,7 +304,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
default:
/* Fall through to handle other weird values too */
std::cout << "Unknown parameter '" << argv[optind-1] << "'" << std::endl;
std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--debug] [--config <config>]" << std::endl <<
std::cout << "Usage: " << argv[0] << " [--nofork] [--nolog] [--nopid] [--debug] [--config <config>]" << std::endl <<
std::string(static_cast<size_t>(8+strlen(argv[0])), ' ') << "[--runasroot] [--version]" << std::endl;
Exit(EXIT_STATUS_ARGV);
break;
@ -325,6 +332,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
Config->cmdline.nofork = (do_nofork != 0);
Config->cmdline.forcedebug = (do_debug != 0);
Config->cmdline.writelog = !do_nolog;
Config->cmdline.writepid = !do_nopid;
if (do_debug)
{