diff options
author | celest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2005-03-18 17:36:03 +0000 |
---|---|---|
committer | celest <celest@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2005-03-18 17:36:03 +0000 |
commit | 8d56be481198093229a7b0febb0231475f4c10f5 (patch) | |
tree | 8bad2602c44f47917ad9a052c04fea59232013d2 /src/common | |
parent | a625c96cd44bc95bdc1d8bc9e2143372fb28c56e (diff) | |
download | hercules-8d56be481198093229a7b0febb0231475f4c10f5.tar.gz hercules-8d56be481198093229a7b0febb0231475f4c10f5.tar.bz2 hercules-8d56be481198093229a7b0febb0231475f4c10f5.tar.xz hercules-8d56be481198093229a7b0febb0231475f4c10f5.zip |
* Fixed a crash when freeing memory of pets
* Added Cygwin support to the -DDUMPSTACK option, and changed its format
* Removed duplicate fopen in login_log
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@1250 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/core.c | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/src/common/core.c b/src/common/core.c index 0b3d65fed..02ba004ae 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -26,6 +26,10 @@ #include "memwatch.h" #endif +char server_type[24]; +int runflag = 1; +unsigned long ticks = 0; // by MC Cameri +char pid_file[256]; static void (*term_func)(void)=NULL; /*====================================== @@ -100,42 +104,58 @@ static void sig_proc(int sn) * Dumps the stack using glibc's backtrace *----------------------------------------- */ -#ifdef CYGWIN - #define sig_dump SIG_DFL // allow cygwin's default dumper utility to handle this -#else -static void sig_dump(int sn) -{ - #ifdef DUMPSTACK - FILE *fp; +#ifndef DUMPSTACK + #define sig_dump SIG_DFL +#else + #ifdef CYGWIN + #define FOPEN_ freopen + extern void cygwin_stackdump(); + #else + #define FOPEN_(fn,m,s) fopen(fn,m) + #endif +extern const char *strsignal(int); +void sig_dump(int sn) +{ + FILE *fp; + char file[256]; + int no = 0; + + #ifndef CYGWIN void* array[20]; - char **stack; - size_t size; - int no = 0; - char tmp[256]; - - // search for a usable filename - do { - sprintf(tmp,"log/stackdump_%04d.txt", ++no); - } while((fp = fopen(tmp,"r")) && (fclose(fp), no < 9999)); - // dump the trace into the file - if ((fp = fopen (tmp,"w")) != NULL) { - - fprintf(fp,"Exception: %s\n", strsignal(sn)); - fprintf(fp,"Stack trace:\n"); - size = backtrace (array, 20); - stack = backtrace_symbols (array, size); - for (no = 0; no < size; no++) { - fprintf(fp, "%s\n", stack[no]); - } - fprintf(fp,"End of stack trace\n"); - - fclose(fp); - aFree(stack); + size_t size; + #endif + + // search for a usable filename + do { + sprintf (file, "log/%s%04d.stackdump", server_type, ++no); + } while((fp = fopen(file,"r")) && (fclose(fp), no < 9999)); + // dump the trace into the file + + if ((fp = FOPEN_(file, "w", stderr)) != NULL) { + printf ("Dumping stack... "); + fprintf(fp, "Exception: %s \n", strsignal(sn)); + fflush (fp); + + + #ifdef CYGWIN + cygwin_stackdump (); + #else + fprintf(fp, "Stack trace:\n"); + size = backtrace (array, 20); + stack = backtrace_symbols (array, size); + for (no = 0; no < size; no++) { + fprintf(fp, "%s\n", stack[no]); } + fprintf(fp,"End of stack trace\n"); + aFree(stack); #endif - //cygwin_stackdump (); - // When pass the signal to the system's default handler + + printf ("Done.\n"); + fflush(stdout); + fclose(fp); + } + // Pass the signal to the system's default handler compat_signal(sn, SIG_DFL); raise(sn); } @@ -202,11 +222,6 @@ static void display_title(void) *-------------------------------------- */ -int runflag = 1; -unsigned long ticks = 0; // by MC Cameri -char pid_file[256]; -char server_type[24]; - void pid_delete(void) { unlink(pid_file); } @@ -289,7 +304,7 @@ int main(int argc,char **argv) display_title(); -#ifndef BCHECK +#ifdef USE_MEMMGR do_init_memmgr(argv[0]); // 一番最初に実行する必要がある #endif |