Mercurial > hg > vamp-plugin-load-checker
changeset 62:e027aa280789
Add signal handler
author | Chris Cannam |
---|---|
date | Thu, 09 Apr 2020 13:49:07 +0100 |
parents | ef64b3f171d9 |
children | 091baff0a983 |
files | src/helper.cpp |
diffstat | 1 files changed, 27 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/helper.cpp Tue Jan 07 11:20:32 2020 +0000 +++ b/src/helper.cpp Thu Apr 09 13:49:07 2020 +0100 @@ -92,15 +92,14 @@ #include <iostream> #include <stdexcept> +static std::string currentSoname = ""; + #ifdef _WIN32 #ifndef UNICODE #error "This must be compiled with UNICODE defined" #endif -static std::string lastLibraryName = ""; - static HMODULE loadLibraryUTF8(std::string name) { - lastLibraryName = name; int n = name.size(); int wn = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), n, 0, 0); wchar_t *wname = new wchar_t[wn+1]; @@ -150,8 +149,8 @@ } } std::size_t pos = s.find("%1"); - if (pos != std::string::npos && lastLibraryName != "") { - s.replace(pos, 2, lastLibraryName); + if (pos != std::string::npos && currentSoname != "") { + s.replace(pos, 2, currentSoname); } return s; } @@ -199,8 +198,6 @@ #endif -//#include <unistd.h> - using namespace std; string error() @@ -335,6 +332,14 @@ #endif } +static void +signalHandler(int signal) +{ + cerr << "Signal " << signal << " caught" << endl; + cout << "FAILURE|" << currentSoname << "|[" << int(PluginCheckCode::FAIL_NOT_LOADABLE) << "]" << endl; + exit(1); +} + int main(int argc, char **argv) { bool allGood = true; @@ -363,6 +368,18 @@ return 2; } + signal(SIGINT, signalHandler); + signal(SIGTERM, signalHandler); + +#ifndef _WIN32 + signal(SIGHUP, signalHandler); + signal(SIGQUIT, signalHandler); + signal(SIGILL, signalHandler); + signal(SIGABRT, signalHandler); + signal(SIGSEGV, signalHandler); + signal(SIGBUS, signalHandler); +#endif + string descriptor = argv[1]; #ifdef _WIN32 @@ -379,6 +396,9 @@ suspendOutput(); while (getline(cin, soname)) { + + currentSoname = soname; + Result result = check(soname, descriptor); resumeOutput(); if (result.code == PluginCheckCode::SUCCESS) {