diff options
author | Adam <Adam@anope.org> | 2010-10-05 19:46:33 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-10-05 19:46:33 -0400 |
commit | 9ab50eedf26f2eb7f3e3d0bc66b41482bd19cba6 (patch) | |
tree | 64a3ee002ae87f498837bcbd22d4867832c74813 /src | |
parent | 64a3bda2356f7396e3d6457359ae1f1ce7bf0325 (diff) |
Fixed restarting Anope when it is started from outside of the services binary dir
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/init.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 24 |
3 files changed, 11 insertions, 16 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1096c6f8..a9f77f40b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -88,7 +88,6 @@ add_dependencies(${PROGRAM_NAME} language headers) # Get the filename of the Anope executable as it is in on this system get_target_property(SERVICES_BINARY ${PROGRAM_NAME} LOCATION) get_filename_component(SERVICES_BINARY ${SERVICES_BINARY} NAME) -set(SERVICES_BIN "${SERVICES_BINARY}") # Add the Anope executable to the list of files for CPack to ignore add_to_cpack_ignored_files("${SERVICES_BINARY}$" TRUE) diff --git a/src/init.cpp b/src/init.cpp index 69bb88539..841fdc55e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -225,7 +225,7 @@ void Init(int ac, char **av) { Log(LOG_TERMINAL) << "Anope-" << Anope::Version() << " -- " << Anope::Build(); Log(LOG_TERMINAL) << "Anope IRC Services (http://www.anope.org)"; - Log(LOG_TERMINAL) << "Usage ./" << SERVICES_BIN << " [options] ..."; + Log(LOG_TERMINAL) << "Usage ./" << services_bin << " [options] ..."; Log(LOG_TERMINAL) << "-c, --config=filename.conf"; Log(LOG_TERMINAL) << "-d, --debug[=level]"; Log(LOG_TERMINAL) << " --dir=services_directory"; diff --git a/src/main.cpp b/src/main.cpp index a1b02a496..fb3b59d1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -186,6 +186,7 @@ void do_restart_services() delete UplinkSock; ModuleManager::UnloadAll(); chdir(binary_dir.c_str()); + my_av[0] = const_cast<char *>(("./" + services_bin).c_str()); execve(services_bin.c_str(), my_av, my_envp); if (!readonly) { @@ -309,7 +310,7 @@ Anope::string GetFullProgDir(const Anope::string &argv0) if (GetModuleFileName(NULL, buffer, PATH_MAX)) { Anope::string fullpath = buffer; - Anope::string::size_type n = fullpath.rfind("\\" SERVICES_BIN); + Anope::string::size_type n = fullpath.rfind("\\"); services_bin = fullpath.substr(n + 1, fullpath.length()); return fullpath.substr(0, n); } @@ -319,20 +320,15 @@ Anope::string GetFullProgDir(const Anope::string &argv0) { Anope::string remainder = argv0; - /* Does argv[0] start with /? If so, it's a full path, use it */ - if (remainder[0] == '/') - { - Anope::string::size_type n = remainder.rfind("/" SERVICES_BIN); - services_bin = remainder.substr(n + 1, remainder.length()); - return remainder.substr(0, n); - } - services_bin = remainder; - if (services_bin.substr(0, 2).equals_cs("./")) - services_bin = services_bin.substr(2); - Anope::string fullpath = Anope::string(buffer) + "/" + remainder; - Anope::string::size_type n = fullpath.rfind("/" SERVICES_BIN); - return fullpath.substr(0, n); + Anope::string::size_type n = services_bin.rfind("/"); + Anope::string fullpath; + if (services_bin[0] == '/') + fullpath = services_bin.substr(0, n); + else + fullpath = Anope::string(buffer) + "/" + services_bin.substr(0, n); + services_bin = services_bin.substr(n + 1, remainder.length()); + return fullpath; } #endif return "/"; |