comparison system/System.cpp @ 1182:a1f410f895d3 3.0-integration

Merge from branch pluginscan
author Chris Cannam
date Fri, 15 Apr 2016 16:26:15 +0100
parents 6b1af0f05f06
children e5a1d815f331
comparison
equal deleted inserted replaced
1175:4018fc0189bc 1182:a1f410f895d3
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 pid_t pid = fork();
340
341 if (pid < 0) {
342 return UnknownPluginLoadStatus; // fork failed
343 }
344
345 if (pid == 0) { // the child process
346
347 void *handle = DLOPEN(soname, RTLD_NOW | RTLD_LOCAL);
348 if (!handle) {
349 cerr << "isPluginLibraryLoadable: Failed to open plugin library \""
350 << soname << "\": " << dlerror() << "\n";
351 cerr << "exiting with status 1" << endl;
352 exit(1);
353 }
354
355 void *fn = DLSYM(handle, descriptorFn.toLocal8Bit().data());
356 if (!fn) {
357 cerr << "isPluginLibraryLoadable: Failed to find plugin descriptor function \"" << descriptorFn << "\" in library \"" << soname << "\": " << dlerror() << "\n";
358 exit(2);
359 }
360
361 // cerr << "isPluginLibraryLoadable: Successfully loaded library \"" << soname << "\" and retrieved descriptor function" << endl;
362
363 exit(0);
364
365 } else { // the parent process
366
367 int status = 0;
368
369 do {
370 waitpid(pid, &status, 0);
371 } while (WIFSTOPPED(status));
372
373 if (WIFEXITED(status)) {
374 switch (WEXITSTATUS(status)) {
375 case 0: return PluginLoadOK; // success
376 case 1: return PluginLoadFailedToLoadLibrary;
377 case 2: return PluginLoadFailedToFindDescriptor;
378 default: return PluginLoadFailedElsewhere;
379 }
380 }
381
382 if (WIFSIGNALED(status)) {
383 return PluginLoadFailedElsewhere;
384 }
385
386 return UnknownPluginLoadStatus;
387 }
388 }
389
390 #endif