summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp4
-rw-r--r--src/main.cpp4
-rw-r--r--src/modulemanager.cpp46
-rw-r--r--src/win32/anope_windows.h4
4 files changed, 36 insertions, 22 deletions
diff --git a/src/init.cpp b/src/init.cpp
index ea0b6c503..721b6aa8e 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -403,6 +403,10 @@ void Init(int ac, char **av)
rand_init();
add_entropy_userkeys();
+#ifdef _WIN32
+ OnStartup();
+#endif
+
/* load modules */
ModuleManager::LoadModuleList(Config->ModulesAutoLoad);
diff --git a/src/main.cpp b/src/main.cpp
index 97ee2a844..df3d217dd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -402,6 +402,10 @@ int main(int ac, char **av, char **envp)
ModuleManager::CleanupRuntimeDirectory();
+#ifdef _WIN32
+ OnShutdown();
+#endif
+
if (restarting)
{
chdir(binary_dir.c_str());
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 82f7cec24..b2907e467 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -84,10 +84,6 @@ void ModuleManager::LoadModuleList(std::list<Anope::string> &ModuleList)
static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &output)
{
Anope::string input = services_dir + "/modules/" + name + ".so";
-
- int source = open(input.c_str(), O_RDONLY);
- if (source == -1)
- return MOD_ERR_NOEXIST;
struct stat s;
if (stat(input.c_str(), &s) == -1)
@@ -95,40 +91,46 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out
else if (!S_ISREG(s.st_mode))
return MOD_ERR_NOEXIST;
+ std::ifstream source(input.c_str(), std::ios_base::in | std::ios_base::binary);
+ if (!source.is_open())
+ return MOD_ERR_NOEXIST;
+
char *tmp_output = strdup(output.c_str());
- int target = mkstemp(tmp_output);
- if (target == -1)
+ int target_fd = mkstemp(tmp_output);
+ if (target_fd == -1 || close(target_fd) == -1)
{
free(tmp_output);
- close(source);
+ source.close();
return MOD_ERR_FILE_IO;
}
output = tmp_output;
free(tmp_output);
Log(LOG_DEBUG) << "Runtime module location: " << output;
+
+ std::ofstream target(output.c_str(), std::ios_base::in | std::ios_base::binary);
+ if (!target.is_open())
+ {
+ source.close();
+ return MOD_ERR_FILE_IO;
+ }
+ int want = s.st_size;
char *buffer = new char[s.st_size];
- bool err = false;
- for (;;)
+ while (want > 0 && !source.fail() && !target.fail())
{
- int read_len = read(source, buffer, s.st_size);
- if (read_len <= 0)
- break;
- int writ_len = write(target, buffer, read_len);
- if (writ_len < 0)
- {
- err = true;
- break;
- }
+ source.read(buffer, want);
+ int read_len = source.gcount();
+
+ target.write(buffer, read_len);
+ want -= read_len;
}
delete [] buffer;
- close(source);
- if (close(target) == -1 || err == true)
- return MOD_ERR_FILE_IO;
+ source.close();
+ target.close();
- return MOD_ERR_OK;
+ return !source.fail() && !target.fail() ? MOD_ERR_OK : MOD_ERR_FILE_IO;
}
/* This code was found online at http://www.linuxjournal.com/article/3687#comment-26593
diff --git a/src/win32/anope_windows.h b/src/win32/anope_windows.h
index 4fe1b11e5..db5f21300 100644
--- a/src/win32/anope_windows.h
+++ b/src/win32/anope_windows.h
@@ -43,6 +43,10 @@
#define vsnprintf _vsnprintf
#define stat _stat
#define S_ISREG(x) ((x) & _S_IFREG)
+#ifdef EINPROGRESS
+# undef EINPROGRESS
+#endif
+#define EINPROGRESS WSAEWOULDBLOCK
#include "sigaction/sigaction.h"