From c8026bc2d73344e1df526f0a80694046efa4b22a Mon Sep 17 00:00:00 2001 From: danieldg Date: Thu, 24 Sep 2009 01:44:29 +0000 Subject: [PATCH] Move configuration filename specification to start script, to reduce hardcoded paths in executable git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11759 e03df62e-2008-0410-955e-edbf42e46eb7 --- .inspircd.inc | 7 ++++++- configure | 1 - include/configreader.h | 2 +- include/inspircd.h | 2 +- src/commands/cmd_rehash.cpp | 6 +++--- src/configreader.cpp | 4 ++-- src/inspircd.cpp | 12 ++++++------ src/server.cpp | 2 +- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.inspircd.inc b/.inspircd.inc index 362bdcf67..91a06ccfd 100644 --- a/.inspircd.inc +++ b/.inspircd.inc @@ -25,7 +25,7 @@ my $version = "@VERSION@"; our($pid,$pidfile); # Lets see what they want to do.. Set the variable (Cause i'm a lazy coder) my $arg = shift(@ARGV); -my $conf = $confpath . "inspircd.conf"; +my $conf; for my $a (@ARGV) { if ($a =~ m/^--config=(.*)$/) @@ -34,6 +34,11 @@ for my $a (@ARGV) last; } } +if (!defined $conf) { + $conf = $confpath . "inspircd.conf"; + push @ARGV, '--config='.$conf; +} + getpidfile($conf); # System for naming script command subs: diff --git a/configure b/configure index 2fc199479..05c4a5e9b 100755 --- a/configure +++ b/configure @@ -928,7 +928,6 @@ sub writefiles { #define CoreExport /**/ #define DllExport /**/ -#define CONFIG_FILE "$config{CONFIG_DIR}/inspircd.conf" #define MOD_PATH "$config{MODULE_DIR}" #define SOMAXCONN_S "$config{_SOMAXCONN}" #define ENTRYPOINT int main(int argc, char** argv) diff --git a/include/configreader.h b/include/configreader.h index 45384b8a3..783af0942 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -698,7 +698,7 @@ class CoreExport ServerConfig : public classbase * @param name Directory to tidy * @return The cleaned filename */ - static char* CleanFilename(char* name); + static const char* CleanFilename(const char* name); /** Check if a file exists. * @param file The full path to a file diff --git a/include/inspircd.h b/include/inspircd.h index 72e49c09a..4c3aba95b 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -432,7 +432,7 @@ class CoreExport InspIRCd : public classbase /** Config file pathname specified on the commandline or via ./configure */ - char ConfigFileName[MAXBUF]; + std::string ConfigFileName; /** Mode handler, handles mode setting and removal */ diff --git a/src/commands/cmd_rehash.cpp b/src/commands/cmd_rehash.cpp index a689801aa..b2a9fbde4 100644 --- a/src/commands/cmd_rehash.cpp +++ b/src/commands/cmd_rehash.cpp @@ -67,15 +67,15 @@ CmdResult CommandRehash::Handle (const std::vector& parameters, Use // Rehash for me. Try to start the rehash thread if (!ServerInstance->ConfigThread) { - std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName) + " on " + ServerInstance->Config->ServerName; + std::string m = user->nick + " is rehashing config file " + ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()) + " on " + ServerInstance->Config->ServerName; ServerInstance->SNO->WriteGlobalSno('a', m); if (IS_LOCAL(user)) user->WriteNumeric(RPL_REHASHING, "%s %s :Rehashing", - user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName)); + user->nick.c_str(),ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str())); else ServerInstance->PI->SendUserNotice(user, std::string("*** Rehashing server ") + - ServerConfig::CleanFilename(ServerInstance->ConfigFileName)); + ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str())); /* Don't do anything with the logs here -- logs are restarted * after the config thread has completed. diff --git a/src/configreader.cpp b/src/configreader.cpp index 5e1dd6969..159ca598f 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -1969,9 +1969,9 @@ bool ServerConfig::FileExists(const char* file) } } -char* ServerConfig::CleanFilename(char* name) +const char* ServerConfig::CleanFilename(const char* name) { - char* p = name + strlen(name); + const char* p = name + strlen(name); while ((p != name) && (*p != '/') && (*p != '\\')) p--; return (p != name ? ++p : p); } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 704fec475..f28324d16 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -328,6 +328,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : HandleIsChannel(this), HandleIsSID(this), HandleRehash(this), + ConfigFileName("inspircd.conf"), /* Functor pointer initialisation. Must match the order of the list above * @@ -428,7 +429,6 @@ InspIRCd::InspIRCd(int argc, char** argv) : srand(this->TIME); *this->LogFileName = 0; - strlcpy(this->ConfigFileName, CONFIG_FILE, MAXBUF); struct option longopts[] = { @@ -454,7 +454,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : break; case 'c': /* Config filename was set */ - strlcpy(ConfigFileName, optarg, MAXBUF); + ConfigFileName = optarg; break; case 0: /* getopt_long_only() set an int variable, just keep going */ @@ -508,7 +508,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : Exit(EXIT_STATUS_LOG); } - if (!ServerConfig::FileExists(this->ConfigFileName)) + if (!ServerConfig::FileExists(ConfigFileName.c_str())) { #ifdef WIN32 /* Windows can (and defaults to) hide file extensions, so let's play a bit nice for windows users. */ @@ -517,13 +517,13 @@ InspIRCd::InspIRCd(int argc, char** argv) : if (ServerConfig::FileExists(txtconf.c_str())) { - strlcat(this->ConfigFileName, ".txt", MAXBUF); + ConfigFileName = txtconf; } else #endif { - printf("ERROR: Cannot open config file: %s\nExiting...\n", this->ConfigFileName); - this->Logs->Log("STARTUP",DEFAULT,"Unable to open config file %s", this->ConfigFileName); + printf("ERROR: Cannot open config file: %s\nExiting...\n", ConfigFileName.c_str()); + this->Logs->Log("STARTUP",DEFAULT,"Unable to open config file %s", ConfigFileName.c_str()); Exit(EXIT_STATUS_CONFIG); } } diff --git a/src/server.cpp b/src/server.cpp index 45834db65..0c0eda6ac 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -50,7 +50,7 @@ void InspIRCd::Exit(int status) void RehashHandler::Call(const std::string &reason) { - Server->SNO->WriteToSnoMask('a', "Rehashing config file %s %s",ServerConfig::CleanFilename(Server->ConfigFileName), reason.c_str()); + Server->SNO->WriteToSnoMask('a', "Rehashing config file %s %s",ServerConfig::CleanFilename(Server->ConfigFileName.c_str()), reason.c_str()); Server->RehashUsersAndChans(); FOREACH_MOD_I(Server, I_OnGarbageCollect, OnGarbageCollect()); if (!Server->ConfigThread) -- 2.39.5