Mercurial > hg > vamp-plugin-load-checker
comparison src/helper.cpp @ 62:e027aa280789
Add signal handler
author | Chris Cannam |
---|---|
date | Thu, 09 Apr 2020 13:49:07 +0100 |
parents | 81ce3ba92b16 |
children | 091baff0a983 |
comparison
equal
deleted
inserted
replaced
61:ef64b3f171d9 | 62:e027aa280789 |
---|---|
90 | 90 |
91 #include <string> | 91 #include <string> |
92 #include <iostream> | 92 #include <iostream> |
93 #include <stdexcept> | 93 #include <stdexcept> |
94 | 94 |
95 static std::string currentSoname = ""; | |
96 | |
95 #ifdef _WIN32 | 97 #ifdef _WIN32 |
96 #ifndef UNICODE | 98 #ifndef UNICODE |
97 #error "This must be compiled with UNICODE defined" | 99 #error "This must be compiled with UNICODE defined" |
98 #endif | 100 #endif |
99 | 101 |
100 static std::string lastLibraryName = ""; | |
101 | |
102 static HMODULE loadLibraryUTF8(std::string name) { | 102 static HMODULE loadLibraryUTF8(std::string name) { |
103 lastLibraryName = name; | |
104 int n = name.size(); | 103 int n = name.size(); |
105 int wn = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), n, 0, 0); | 104 int wn = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), n, 0, 0); |
106 wchar_t *wname = new wchar_t[wn+1]; | 105 wchar_t *wname = new wchar_t[wn+1]; |
107 wn = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), n, wname, wn); | 106 wn = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), n, wname, wn); |
108 wname[wn] = L'\0'; | 107 wname[wn] = L'\0'; |
148 if (s[i] == '\n' || s[i] == '\r') { | 147 if (s[i] == '\n' || s[i] == '\r') { |
149 s.erase(i, 1); | 148 s.erase(i, 1); |
150 } | 149 } |
151 } | 150 } |
152 std::size_t pos = s.find("%1"); | 151 std::size_t pos = s.find("%1"); |
153 if (pos != std::string::npos && lastLibraryName != "") { | 152 if (pos != std::string::npos && currentSoname != "") { |
154 s.replace(pos, 2, lastLibraryName); | 153 s.replace(pos, 2, currentSoname); |
155 } | 154 } |
156 return s; | 155 return s; |
157 } | 156 } |
158 | 157 |
159 #define DLOPEN(a,b) loadLibraryUTF8(a) | 158 #define DLOPEN(a,b) loadLibraryUTF8(a) |
197 } | 196 } |
198 } | 197 } |
199 | 198 |
200 #endif | 199 #endif |
201 | 200 |
202 //#include <unistd.h> | |
203 | |
204 using namespace std; | 201 using namespace std; |
205 | 202 |
206 string error() | 203 string error() |
207 { | 204 { |
208 return DLERROR(); | 205 return DLERROR(); |
333 #else | 330 #else |
334 dup2(normalFd, 1); | 331 dup2(normalFd, 1); |
335 #endif | 332 #endif |
336 } | 333 } |
337 | 334 |
335 static void | |
336 signalHandler(int signal) | |
337 { | |
338 cerr << "Signal " << signal << " caught" << endl; | |
339 cout << "FAILURE|" << currentSoname << "|[" << int(PluginCheckCode::FAIL_NOT_LOADABLE) << "]" << endl; | |
340 exit(1); | |
341 } | |
342 | |
338 int main(int argc, char **argv) | 343 int main(int argc, char **argv) |
339 { | 344 { |
340 bool allGood = true; | 345 bool allGood = true; |
341 string soname; | 346 string soname; |
342 | 347 |
361 "in each library (e.g. vampGetPluginDescriptor for Vamp plugins). The list of\n" | 366 "in each library (e.g. vampGetPluginDescriptor for Vamp plugins). The list of\n" |
362 "candidate plugin library filenames is read from stdin.\n" << endl; | 367 "candidate plugin library filenames is read from stdin.\n" << endl; |
363 return 2; | 368 return 2; |
364 } | 369 } |
365 | 370 |
371 signal(SIGINT, signalHandler); | |
372 signal(SIGTERM, signalHandler); | |
373 | |
374 #ifndef _WIN32 | |
375 signal(SIGHUP, signalHandler); | |
376 signal(SIGQUIT, signalHandler); | |
377 signal(SIGILL, signalHandler); | |
378 signal(SIGABRT, signalHandler); | |
379 signal(SIGSEGV, signalHandler); | |
380 signal(SIGBUS, signalHandler); | |
381 #endif | |
382 | |
366 string descriptor = argv[1]; | 383 string descriptor = argv[1]; |
367 | 384 |
368 #ifdef _WIN32 | 385 #ifdef _WIN32 |
369 // Avoid showing the error-handler dialog for missing DLLs, | 386 // Avoid showing the error-handler dialog for missing DLLs, |
370 // failing quietly instead. It's permissible for this program | 387 // failing quietly instead. It's permissible for this program |
377 | 394 |
378 initFds(); | 395 initFds(); |
379 suspendOutput(); | 396 suspendOutput(); |
380 | 397 |
381 while (getline(cin, soname)) { | 398 while (getline(cin, soname)) { |
399 | |
400 currentSoname = soname; | |
401 | |
382 Result result = check(soname, descriptor); | 402 Result result = check(soname, descriptor); |
383 resumeOutput(); | 403 resumeOutput(); |
384 if (result.code == PluginCheckCode::SUCCESS) { | 404 if (result.code == PluginCheckCode::SUCCESS) { |
385 cout << "SUCCESS|" << soname << "|" << endl; | 405 cout << "SUCCESS|" << soname << "|" << endl; |
386 } else { | 406 } else { |