mirror of
https://github.com/anope/anope.git
synced 2026-07-01 01:46:39 +02:00
Fixed Windows runtime problems
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@
|
||||
# define dlsym(file, symbol) (HMODULE)GetProcAddress(file, symbol)
|
||||
# define dlclose(file) FreeLibrary(file) ? 0 : 1
|
||||
# define ano_modclearerr() SetLastError(0)
|
||||
# define ano_moderr() Anope::LastError().c_str()
|
||||
# define ano_moderr() (Anope::LastError().empty() ? NULL : Anope::LastError().c_str())
|
||||
#else
|
||||
typedef void * ano_module_t;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
+26
-24
@@ -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;
|
||||
|
||||
char *buffer = new char[s.st_size];
|
||||
bool err = false;
|
||||
for (;;)
|
||||
|
||||
std::ofstream target(output.c_str(), std::ios_base::in | std::ios_base::binary);
|
||||
if (!target.is_open())
|
||||
{
|
||||
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.close();
|
||||
return MOD_ERR_FILE_IO;
|
||||
}
|
||||
|
||||
int want = s.st_size;
|
||||
char *buffer = new char[s.st_size];
|
||||
while (want > 0 && !source.fail() && !target.fail())
|
||||
{
|
||||
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
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user