From fe33eabc47f48759ebb9444df96bce54f03e83cb Mon Sep 17 00:00:00 2001 From: codemastr Date: Wed, 25 Apr 2001 21:21:33 +0000 Subject: [PATCH] Win32 fixes --- Changes | 2 + src/ircd.c | 12 +++-- src/win32/Win32GUI.c | 116 +++++++++++++++++++++++-------------------- 3 files changed, 70 insertions(+), 60 deletions(-) diff --git a/Changes b/Changes index d72b4ef81..2a8145912 100644 --- a/Changes +++ b/Changes @@ -446,3 +446,5 @@ - Removed newdns - Fixed a memory bug in win32 code found and fixed by McSkaf, and fixed a typo - Fixed a win32 bug found by RaYmAn causing the tray icon not to be displayed sometimes +- Fixed a bunch of Win32 bugs reported and fixed by McSkaf +- Made the IRCd delete its tray icon in win32 on SIGSEGV diff --git a/src/ircd.c b/src/ircd.c index 795a1ad8a..e8a754442 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -106,7 +106,9 @@ aClient me; /* That's me */ char *me_hash; aClient *client = &me; /* Pointer to beginning of Client list */ extern char backupbuf[8192]; - +#ifdef _WIN32 +extern void CleanUpSegv(int sig); +#endif #ifndef NO_FDLIST fdlist default_fdlist; fdlist busycli_fdlist; @@ -793,9 +795,7 @@ int InitwIRCD(argc, argv) WSAStartup(wVersionRequested, &wsaData); #endif bzero((char *)&me, sizeof(me)); -#ifndef _WIN32 setup_signals(); -#endif initload(); init_ircstats(); clear_scache_hash_table(); @@ -1498,9 +1498,9 @@ static void open_debugfile() return; } -#ifndef _WIN32 static void setup_signals() { +#ifndef _WIN32 #ifdef POSIX_SIGNALS struct sigaction act; act.sa_handler = SIG_IGN; @@ -1557,6 +1557,8 @@ static void setup_signals() */ (void)siginterrupt(SIGALRM, 1); #endif +#else + (void)signal(SIGSEGV,CleanUpSegv); +#endif } -#endif /* !_Win32 */ diff --git a/src/win32/Win32GUI.c b/src/win32/Win32GUI.c index 88b89b582..bdb67e163 100644 --- a/src/win32/Win32GUI.c +++ b/src/win32/Win32GUI.c @@ -78,7 +78,10 @@ void CleanUp(void) { Shell_NotifyIcon(NIM_DELETE ,&SysTray); } - +void CleanUpSegv(int sig) +{ + Shell_NotifyIcon(NIM_DELETE ,&SysTray); +} HWND hwIRCDWnd=NULL/* hwnd=NULL*/; HWND hwTreeView; HANDLE hMainThread = 0; @@ -473,16 +476,17 @@ LRESULT CALLBACK ConfigDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam char *buffer = '\0'; struct stat sb; SetWindowText(hDlg, "UnrealIRCd Configuration File"); - fd = open(CPATH, _O_RDONLY|_O_BINARY); - fstat(fd,&sb); - /* Only allocate the amount we need */ - buffer = (char *)malloc(sb.st_size+1); - buffer[0] = 0; - len = read(fd, buffer, sb.st_size); - buffer[len] = 0; - SetDlgItemText(hDlg, IDC_TEXT, buffer); - close(fd); - free(buffer); + if ((fd = open(CPATH, _O_RDONLY|_O_BINARY)) != -1) { + fstat(fd,&sb); + /* Only allocate the amount we need */ + buffer = (char *)malloc(sb.st_size+1); + buffer[0] = 0; + len = read(fd, buffer, sb.st_size); + buffer[len] = 0; + SetDlgItemText(hDlg, IDC_TEXT, buffer); + close(fd); + free(buffer); + } return (TRUE); } case WM_COMMAND: @@ -504,10 +508,6 @@ LRESULT CALLBACK ConfigDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam } break; - case WM_CHAR: -MessageBox(NULL, (char *)wParam, (char *)wParam, MB_OK); -break; - case WM_CLOSE: EndDialog(hDlg, TRUE); break; @@ -522,16 +522,17 @@ LRESULT CALLBACK MotdDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) int fd,len; char *buffer = '\0'; SetWindowText(hDlg, "UnrealIRCd MOTD File"); - fd = open(MPATH, _O_RDONLY|_O_BINARY); - fstat(fd,&sb); - /* Only allocate the amount we need */ - buffer = (char *)malloc(sb.st_size+1); - buffer[0] = 0; - len = read(fd, buffer, sb.st_size); - buffer[len] = 0; - SetDlgItemText(hDlg, IDC_TEXT, buffer); - close(fd); - free(buffer); + if ((fd = open(MPATH, _O_RDONLY|_O_BINARY)) != -1) { + fstat(fd,&sb); + /* Only allocate the amount we need */ + buffer = (char *)malloc(sb.st_size+1); + buffer[0] = 0; + len = read(fd, buffer, sb.st_size); + buffer[len] = 0; + SetDlgItemText(hDlg, IDC_TEXT, buffer); + close(fd); + free(buffer); + } return (TRUE); } case WM_COMMAND: @@ -567,16 +568,17 @@ LRESULT CALLBACK OperMotdDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar int fd,len; char *buffer = '\0'; SetWindowText(hDlg, "UnrealIRCd OperMOTD File"); - fd = open(OPATH, _O_RDONLY|_O_BINARY); - fstat(fd,&sb); - /* Only allocate the amount we need */ - buffer = (char *)malloc(sb.st_size+1); - buffer[0] = 0; - len = read(fd, buffer, sb.st_size); - buffer[len] = 0; - SetDlgItemText(hDlg, IDC_TEXT, buffer); - close(fd); - free(buffer); + if ((fd = open(OPATH, _O_RDONLY|_O_BINARY)) != -1) { + fstat(fd,&sb); + /* Only allocate the amount we need */ + buffer = (char *)malloc(sb.st_size+1); + buffer[0] = 0; + len = read(fd, buffer, sb.st_size); + buffer[len] = 0; + SetDlgItemText(hDlg, IDC_TEXT, buffer); + close(fd); + free(buffer); + } return (TRUE); } case WM_COMMAND: @@ -612,16 +614,17 @@ LRESULT CALLBACK BotMotdDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPara int fd,len; char *buffer = '\0'; SetWindowText(hDlg, "UnrealIRCd BotMOTD File"); - fd = open(BPATH, _O_RDONLY|_O_BINARY); - fstat(fd,&sb); - /* Only allocate the amount we need */ - buffer = (char *)malloc(sb.st_size+1); - buffer[0] = 0; - len = read(fd, buffer, sb.st_size); - buffer[len] = 0; - SetDlgItemText(hDlg, IDC_TEXT, buffer); - close(fd); - free(buffer); + if ((fd = open(BPATH, _O_RDONLY|_O_BINARY)) != -1) { + fstat(fd,&sb); + /* Only allocate the amount we need */ + buffer = (char *)malloc(sb.st_size+1); + buffer[0] = 0; + len = read(fd, buffer, sb.st_size); + buffer[len] = 0; + SetDlgItemText(hDlg, IDC_TEXT, buffer); + close(fd); + free(buffer); + } return (TRUE); } case WM_COMMAND: @@ -657,16 +660,17 @@ LRESULT CALLBACK RulesDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) int fd,len; char *buffer = '\0'; SetWindowText(hDlg, "UnrealIRCd Rules File"); - fd = open(RPATH, _O_RDONLY|_O_BINARY); - fstat(fd,&sb); - /* Only allocate the amount we need */ - buffer = (char *)malloc(sb.st_size+1); - buffer[0] = 0; - len = read(fd, buffer, sb.st_size); - buffer[len] = 0; - SetDlgItemText(hDlg, IDC_TEXT, buffer); - close(fd); - free(buffer); + if ((fd = open(RPATH, _O_RDONLY|_O_BINARY)) != -1) { + fstat(fd,&sb); + /* Only allocate the amount we need */ + buffer = (char *)malloc(sb.st_size+1); + buffer[0] = 0; + len = read(fd, buffer, sb.st_size); + buffer[len] = 0; + SetDlgItemText(hDlg, IDC_TEXT, buffer); + close(fd); + free(buffer); + } return (TRUE); } case WM_COMMAND: @@ -846,6 +850,7 @@ void win_log(char *format, ...) { buf2 = MyMalloc(strlen(errors)+strlen(buf)+1); sprintf(buf2, "%s%s",errors,buf); MyFree(errors); + errors = NULL; } else { buf2 = MyMalloc(strlen(buf)+1); @@ -866,6 +871,7 @@ LRESULT CALLBACK ConfigErrorDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM l MessageBeep(MB_ICONEXCLAMATION); SetDlgItemText(hDlg, IDC_CONFIGERROR, errors); MyFree(errors); + errors = NULL; return (TRUE); case WM_COMMAND: