Permalink
Browse files

Fixed windows error handling for plugin manager, classes which overlo…

…ad integer methods should be explicit to prevent implicit casting to the wrong method
  • Loading branch information...
1 parent 348aa27 commit a0bae9924b0288c0d4a02e0285ba147ae78e9074 @Justasic Justasic committed Jun 13, 2012
Showing with 17 additions and 149 deletions.
  1. +6 −6 include/nbt.h
  2. +10 −1 include/plugin.h
  3. +1 −1 src/screenBase.cpp
  4. +0 −141 src/signal.cpp
View
@@ -55,12 +55,12 @@ class NBT_Value
};
NBT_Value(eTAG_Type type, eTAG_Type listType = TAG_END);
- NBT_Value(int8_t value);
- NBT_Value(int16_t value);
- NBT_Value(int32_t value);
- NBT_Value(int64_t value);
- NBT_Value(float value);
- NBT_Value(double value);
+ explicit NBT_Value(int8_t value);
+ explicit NBT_Value(int16_t value);
+ explicit NBT_Value(int32_t value);
+ explicit NBT_Value(int64_t value);
+ explicit NBT_Value(float value);
+ explicit NBT_Value(double value);
NBT_Value(int32_t* buf, int32_t len);
NBT_Value(uint8_t* buf, int32_t len);
View
@@ -64,7 +64,16 @@
#define LIBRARY_LOAD(x) LoadLibrary(x)
#define LIBRARY_SELF() GetModuleHandle(NULL)
#define LIBRARY_SYMBOL(x, y) GetProcAddress(x, y)
-#define LIBRARY_ERROR() "Windows error handling needs work!" // <- NOTE
+char *LIBRARY_ERROR(void)
+{
+ char errbuf[513];
+ DWORD err = GetLastError();
+ if(!err)
+ return NULL;
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, errbuf, 512, NULL);
+ SetLastError(0);
+ return errbuf;
+}
#define LIBRARY_CLOSE(x) FreeLibrary(x)
#define LIBRARY_EXTENSION ".dll"
#else
View
@@ -28,7 +28,7 @@
#include "screenBase.h"
#include <ctime>
-Screen::~Screen(void) {}
+Screen::~Screen() {}
std::string Screen::currentTimestamp(bool seconds)
{
View
@@ -1,141 +0,0 @@
-/*
- Copyright (c) 2012, The Mineserver Project
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the The Mineserver Project nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#include "Signal.h"
-#include "mineserver.h"
-#include "constants.h"
-#include "logger.h"
-#include <cstdio>
-#include <sstream>
-#include <iostream>
-#include <errno.h>
-#include <cstring>
-#include <cstdlib>
-#include <ctime>
-#include <signal.h>
-
-#ifndef SIGBREK
-# define SIGBREAK 0 // Define this for unix systems
-#endif
-char segv_location[255];
-
-void SignalHandler(int);
-
-void InitSignals()
-{
- signal(SIGTERM, SignalHandler); // Justasic: Terminate signal sent by kill
- signal(SIGKILL, SignalHandler); // Justasic: Kill signal sent by kill or kernel i think
- signal(SIGINT, SignalHandler); // Justasic: Signal Interrupt, usually a CTRL+C at console
- signal(SIGHUP, SignalHandler); // Justasic: Signal Hangup, typically used as a Config Rehash
- signal(SIGBREAK, SignalHandler); // Justasic: ?? is this like sigterm?
- #ifdef HAVE_BACKTRACE
- signal(SIGSEGV, SignalHandler); // Justasic: Segmentation Fault signal, used for generating segfault reports
- #endif
-}
-
-void HandleSegfault()
-{
- // Justasic: We only use this statement if we have the capability of outputting a backtrace >.<
- // Justasic: import some crap from another project i did this to.
- #ifdef HAVE_BACKTRACE
- void *array[10];
- char **strings;
- char tbuf[256];
- size_t size;
- time_t now = time(NULL);
- size = backtrace(array, 10);
-
- #ifdef HAVE_SYS_UTSNAME_H
- struct utsname uts;
- if(uname(&uts) < 0)
- std::cerr << "uname() error: " << strerror(errno) << std::endl;
- #endif
-
- strftime(tbuf, sizeof(tbuf), "[%b %d %H:%M:%S %Y]", localtime(&now));
- std::stringstream slog;
- slog << "====================== Segmentation Fault ======================" << std::endl;
- slog << "Please note that the Mineserver developers may ask you to re-run this under gdb!" << std::endl;
- slog << "Time of crash: " << tbuf << std::endl;
- slog << "Mineserver version: " << VERSION_COMPLETE << std::endl;
- #ifdef HAVE_SYS_UTSNAME_H
- slog << "System info: " << uts.sysname << " " << uts.nodename << " " << uts.release << " " << uts.machine << std::endl;
- slog << "System version: " << uts.version << std::endl;
- #endif
- slog << "C++ Version: " << __VERSION__ << std::endl; // GCC only? hmmnn
- //slog << "Socket Buffer: " << LastBuf << std::endl; // Use this for the last thing sent/received by the socket.
- slog << "Location: " << segv_location << std::endl;
- strings = backtrace_symbols(array, size);
-
- for(unsigned i=1; i < size; i++)
- slog << "BackTrace(" << (i - 1) << "): " << strings[i] << std::endl;
-
- free(strings);
- slog << "======================== END OF REPORT ==========================" << std::endl;
-
- // FIXME: Maybe log to a file somewhere instead of crashing?
- std::cout << slog.str(); //Write to terminal.
- std::cout.flush(); //Clear output
- #endif // HAVE_BACKTRACE
-
- Mineserver::get()->stop();
- exit(SIGSEGV); // Exit so we're not still running
-}
-
-// TODO: On signal event: close active connections, save world, etc.
-void SignalHandler(int sig)
-{
- switch(sig)
- {
- case SIGHUP:
- signal(sig, SIG_IGN);
- /* TODO: Rehash a config? hmmnn */
- LOG2(INFO, "Received SIGHUP, rehashing..");
- break;
-#ifdef HAVE_BACKTRACE
- case SIGSEGV:
- // Justasic: You can stop SIGSEGV's but I HIGHLY recommend against it unless you have good reason to.
- // Justasic: as that can cause stack corruption and all kinds of bad things. if you do, use setjmp >.>
- HandleSegfault();
- break;
-#endif
- case SIGPIPE:
- // Justasic: Ignore sigpipe since it just gets in the way.
- signal(sig, SIG_IGN);
- break;
- case SIGINT:
- case SIGKILL:
- case SIGBREAK:
- case SIGTERM:
- signal(sig, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
- LOG2(INFO, "Received SIGTERM, Exiting..");
- Mineserver::get()->stop();
- break;
- default:
- static_cast<void>(0); // TODO: fix this to do something useful?
- }
-}

0 comments on commit a0bae99

Please sign in to comment.