Mercurial > hg > svcore
comparison system/System.cpp @ 1178:bf05d9259dbc pluginscan
First cut running (but not yet using output of, or recovering from errors in) the plugin checker at startup
author | Chris Cannam |
---|---|
date | Thu, 14 Apr 2016 12:12:04 +0100 |
parents | afed8be79032 |
children | 6b1af0f05f06 |
comparison
equal
deleted
inserted
replaced
1175:4018fc0189bc | 1178:bf05d9259dbc |
---|---|
333 PluginLoadStatus | 333 PluginLoadStatus |
334 TestPluginLoadability(QString soname, QString descriptorFn) | 334 TestPluginLoadability(QString soname, QString descriptorFn) |
335 { | 335 { |
336 //!!! This is POSIX only, no equivalent on Windows, where we'll | 336 //!!! This is POSIX only, no equivalent on Windows, where we'll |
337 //!!! have to do something completely different | 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). | |
338 | 343 |
339 pid_t pid = fork(); | 344 pid_t pid = fork(); |
340 | 345 |
341 if (pid < 0) { | 346 if (pid < 0) { |
342 return UnknownPluginLoadStatus; // fork failed | 347 return UnknownPluginLoadStatus; // fork failed |
343 } | 348 } |
344 | 349 |
345 if (pid == 0) { // the child process | 350 if (pid == 0) { // the child process |
346 | 351 |
352 cerr << "isPluginLibraryLoadable: About to try library \"" << soname << "\"" << endl; | |
353 | |
347 void *handle = DLOPEN(soname, RTLD_NOW | RTLD_LOCAL); | 354 void *handle = DLOPEN(soname, RTLD_NOW | RTLD_LOCAL); |
348 if (!handle) { | 355 if (!handle) { |
349 cerr << "isPluginLibraryLoadable: Failed to open plugin library \"" | 356 cerr << "isPluginLibraryLoadable: Failed to open plugin library \"" |
350 << soname << "\": " << dlerror() << "\n"; | 357 << soname << "\": " << dlerror() << "\n"; |
351 cerr << "exiting with status 1" << endl; | 358 cerr << "exiting with status 1" << endl; |
356 if (!fn) { | 363 if (!fn) { |
357 cerr << "isPluginLibraryLoadable: Failed to find plugin descriptor function \"" << descriptorFn << "\" in library \"" << soname << "\": " << dlerror() << "\n"; | 364 cerr << "isPluginLibraryLoadable: Failed to find plugin descriptor function \"" << descriptorFn << "\" in library \"" << soname << "\": " << dlerror() << "\n"; |
358 exit(2); | 365 exit(2); |
359 } | 366 } |
360 | 367 |
361 // cerr << "isPluginLibraryLoadable: Successfully loaded library \"" << soname << "\" and retrieved descriptor function" << endl; | 368 cerr << "isPluginLibraryLoadable: Successfully loaded library \"" << soname << "\" and retrieved descriptor function" << endl; |
362 | 369 |
363 exit(0); | 370 exit(0); |
364 | 371 |
365 } else { // the parent process | 372 } else { // the parent process |
366 | 373 |
367 int status = 0; | 374 int status = 0; |
368 | 375 |
369 do { | 376 do { |
377 cerr << "waiting for subprocess with pid " << pid << "..." << endl; | |
370 waitpid(pid, &status, 0); | 378 waitpid(pid, &status, 0); |
379 cerr << "waited" << endl; | |
371 } while (WIFSTOPPED(status)); | 380 } while (WIFSTOPPED(status)); |
381 | |
382 cerr << "and finished" << endl; | |
372 | 383 |
373 if (WIFEXITED(status)) { | 384 if (WIFEXITED(status)) { |
374 switch (WEXITSTATUS(status)) { | 385 switch (WEXITSTATUS(status)) { |
375 case 0: return PluginLoadOK; // success | 386 case 0: return PluginLoadOK; // success |
376 case 1: return PluginLoadFailedToLoadLibrary; | 387 case 1: return PluginLoadFailedToLoadLibrary; |