diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/os_restart.c | 4 | ||||
-rw-r--r-- | src/main.c | 34 | ||||
-rw-r--r-- | src/users.c | 5 |
3 files changed, 26 insertions, 17 deletions
diff --git a/src/core/os_restart.c b/src/core/os_restart.c index 8de76c1c4..b80f88c5a 100644 --- a/src/core/os_restart.c +++ b/src/core/os_restart.c @@ -24,7 +24,6 @@ class CommandOSRestart : public Command CommandReturn Execute(User *u, std::vector<ci::string> ¶ms) { -#ifdef SERVICES_BIN quitmsg = new char[31 + strlen(u->nick)]; if (!quitmsg) quitmsg = "RESTART command received, but out of memory!"; @@ -35,9 +34,6 @@ class CommandOSRestart : public Command oper_global(NULL, "%s", GlobalOnCycleMessage); /* raise(SIGHUP); */ do_restart_services(); -#else - notice_lang(s_OperServ, u, OPER_CANNOT_RESTART); -#endif return MOD_CONT; } diff --git a/src/main.c b/src/main.c index a8ee4aeb1..5fcfe3a1c 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,8 @@ /* Command-line options: (note that configuration variables are in config.c) */ std::string services_dir; /* -dir dirname */ +std::string services_bin; /* Binary as specified by the user */ +std::string orig_cwd; /* Original current working directory */ const char *log_filename = LOG_FILENAME; /* -log filename */ int debug = 0; /* -debug */ int readonly = 0; /* -readonly */ @@ -175,8 +177,8 @@ void do_restart_services() /* First don't unload protocol module, then do so */ modules_unload_all(false); modules_unload_all(true); - chdir(binary_dir.c_str()); - execve(SERVICES_BIN, my_av, my_envp); + chdir(orig_cwd.c_str()); + execve(services_bin.c_str(), my_av, my_envp); if (!readonly) { open_log(); log_perror("Restart failed"); @@ -324,6 +326,7 @@ std::string GetFullProgDir(char *argv0) if (GetModuleFileName(NULL, buffer, PATH_MAX)) { std::string fullpath = buffer; + services_dir = fullpath.substr(orig_cwd.size() + 1); std::string::size_type n = fullpath.rfind("\\" SERVICES_BIN); return std::string(fullpath, 0, n); } @@ -336,10 +339,12 @@ std::string GetFullProgDir(char *argv0) /* Does argv[0] start with /? If so, it's a full path, use it */ if (remainder[0] == '/') { + services_bin = remainder.substr(orig_cwd.size() + 1); std::string::size_type n = remainder.rfind("/" SERVICES_BIN); return std::string(remainder, 0, n); } + services_bin = remainder; std::string fullpath = static_cast<std::string>(buffer) + "/" + remainder; std::string::size_type n = fullpath.rfind("/" SERVICES_BIN); return std::string(fullpath, 0, n); @@ -365,6 +370,14 @@ int main(int ac, char **av, char **envp) my_av = av; my_envp = envp; + char cwd[PATH_MAX] = ""; +#ifdef _WIN32 + GetCurrentDirectory(PATH_MAX, cwd); +#else + getcwd(cwd, PATH_MAX); +#endif + orig_cwd = cwd; + #ifndef _WIN32 /* If we're root, issue a warning now */ if ((getuid() == 0) && (getgid() == 0)) { @@ -377,7 +390,13 @@ int main(int ac, char **av, char **envp) #endif binary_dir = GetFullProgDir(av[0]); - services_dir = binary_dir + "/../data"; +#ifdef _WIN32 + std::string::size_type n = binary_dir.rfind("\\"); + services_dir = binary_dir.substr(0, n) + "\\data"; +#else + std::string::size_type n = binary_dir.rfind("/"); + services_dir = binary_dir.substr(0, n) + "/data"; +#endif /* Clean out the module runtime directory prior to running, just in case files were left behind during a previous run */ ModuleRunTimeDirCleanUp(); @@ -496,25 +515,20 @@ int main(int ac, char **av, char **envp) /* Check for restart instead of exit */ if (save_data == -2) { -#ifdef SERVICES_BIN alog("Restarting"); if (!quitmsg) quitmsg = "Restarting"; ircdproto->SendSquit(ServerName, quitmsg); disconn(servsock); close_log(); - chdir(binary_dir.c_str()); - execve(SERVICES_BIN, av, envp); + chdir(orig_cwd.c_str()); + execve(services_bin.c_str(), av, envp); if (!readonly) { open_log(); log_perror("Restart failed"); close_log(); } return 1; -#else - quitmsg = - "Restart attempt failed--SERVICES_BIN not defined (rerun configure)"; -#endif } /* Disconnect and exit */ diff --git a/src/users.c b/src/users.c index f6510ae3d..c019c136b 100644 --- a/src/users.c +++ b/src/users.c @@ -183,8 +183,7 @@ void User::SetRealname(const std::string &srealname) this->realname = sstrdup(srealname.c_str()); NickAlias *na = findnick(this->nick); - if (na && (nick_identified(this) || - (!(this->nc->flags & NI_SECURE) && nick_recognized(this)))) + if (na && (nick_identified(this) || (!this->nc || (this->nc && !(this->nc->flags & NI_SECURE) && nick_recognized(this))))) { if (na->last_realname) delete [] na->last_realname; @@ -591,7 +590,7 @@ User *do_nick(const char *source, const char *nick, const char *username, const } delete [] logrealname; } - + /* Allocate User structure and fill it in. */ user = new User(nick, uid ? uid : ""); user->SetIdent(username); |