comparison system/System.cpp @ 1179:6b1af0f05f06 pluginscan

Make use of, and warn for, the plugin checker for all types of plugin. Haven't yet resolved the question of how to install and find it.
author Chris Cannam
date Thu, 14 Apr 2016 14:03:18 +0100
parents bf05d9259dbc
children e5a1d815f331
comparison
equal deleted inserted replaced
1178:bf05d9259dbc 1179:6b1af0f05f06
323 float modf(float x, float y) { return x - (y * floorf(x / y)); } 323 float modf(float x, float y) { return x - (y * floorf(x / y)); }
324 324
325 double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; } 325 double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; }
326 float princargf(float a) { return float(princarg(a)); } 326 float princargf(float a) { return float(princarg(a)); }
327 327
328 #ifndef _WIN32
329
330 #include <unistd.h>
331 #include <sys/wait.h>
332
333 PluginLoadStatus
334 TestPluginLoadability(QString soname, QString descriptorFn)
335 {
336 //!!! This is POSIX only, no equivalent on Windows, where we'll
337 //!!! have to do something completely different
338
339 //!!! update -- this is a bad idea on POSIX systems as well, I
340 //!!! fear, because fork() generally doesn't mix with
341 //!!! multithreaded processes (it forks only one thread but any
342 //!!! locked mutexes from the other threads remain locked).
343
344 pid_t pid = fork();
345
346 if (pid < 0) {
347 return UnknownPluginLoadStatus; // fork failed
348 }
349
350 if (pid == 0) { // the child process
351
352 cerr << "isPluginLibraryLoadable: About to try library \"" << soname << "\"" << endl;
353
354 void *handle = DLOPEN(soname, RTLD_NOW | RTLD_LOCAL);
355 if (!handle) {
356 cerr << "isPluginLibraryLoadable: Failed to open plugin library \""
357 << soname << "\": " << dlerror() << "\n";
358 cerr << "exiting with status 1" << endl;
359 exit(1);
360 }
361
362 void *fn = DLSYM(handle, descriptorFn.toLocal8Bit().data());
363 if (!fn) {
364 cerr << "isPluginLibraryLoadable: Failed to find plugin descriptor function \"" << descriptorFn << "\" in library \"" << soname << "\": " << dlerror() << "\n";
365 exit(2);
366 }
367
368 cerr << "isPluginLibraryLoadable: Successfully loaded library \"" << soname << "\" and retrieved descriptor function" << endl;
369
370 exit(0);
371
372 } else { // the parent process
373
374 int status = 0;
375
376 do {
377 cerr << "waiting for subprocess with pid " << pid << "..." << endl;
378 waitpid(pid, &status, 0);
379 cerr << "waited" << endl;
380 } while (WIFSTOPPED(status));
381
382 cerr << "and finished" << endl;
383
384 if (WIFEXITED(status)) {
385 switch (WEXITSTATUS(status)) {
386 case 0: return PluginLoadOK; // success
387 case 1: return PluginLoadFailedToLoadLibrary;
388 case 2: return PluginLoadFailedToFindDescriptor;
389 default: return PluginLoadFailedElsewhere;
390 }
391 }
392
393 if (WIFSIGNALED(status)) {
394 return PluginLoadFailedElsewhere;
395 }
396
397 return UnknownPluginLoadStatus;
398 }
399 }
400
401 #endif