summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char/char.c12
-rw-r--r--src/common/core.c7
2 files changed, 18 insertions, 1 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 37580b6..08ad642 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -720,8 +720,20 @@ void mmo_char_sync(void) {
// Function to save (in a periodic way) datas in files
//----------------------------------------------------
int mmo_char_sync_timer(int tid, unsigned int tick, int id, int data) {
+ pid_t pid;
+
+ // This can take a lot of time. Fork a child to handle the work and return at once
+ // If we're unable to fork just continue running the function normally
+ if ((pid = fork()) > 0)
+ return 0;
+
mmo_char_sync();
inter_save();
+
+ // If we're a child we should suicide now.
+ if (pid == 0)
+ exit(0);
+
return 0;
}
diff --git a/src/common/core.c b/src/common/core.c
index 2546f4e..7267d8f 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -7,6 +7,7 @@
#include <unistd.h>
#endif
#include <signal.h>
+#include <wait.h>
#include "core.h"
#include "socket.h"
@@ -48,6 +49,9 @@ static void sig_proc(int sn)
}
exit(0);
break;
+ case SIGCHLD:
+ wait(&i);
+ break;
}
}
@@ -135,7 +139,8 @@ int main(int argc,char **argv)
compat_signal(SIGPIPE,SIG_IGN);
compat_signal(SIGTERM,sig_proc);
compat_signal(SIGINT,sig_proc);
-
+ compat_signal(SIGCHLD,sig_proc);
+
// Signal to create coredumps by system when necessary (crash)
compat_signal(SIGSEGV, SIG_DFL);
#ifndef LCCWIN32