void init(MemoryMode mode, int prealloc) { QMutexLocker locker(global_mutex()); if(global) { ++(global->refs); return; } bool allow_mmap_fallback = false; bool drop_root = false; if(mode == Practical) { allow_mmap_fallback = true; drop_root = true; } else if(mode == Locking) drop_root = true; bool secmem = botan_init(prealloc, allow_mmap_fallback); if(drop_root) { #ifdef Q_OS_UNIX setuid(getuid()); #endif } global = new Global; global->secmem = secmem; ++(global->refs); // for maximum setuid safety, qca should be initialized before qapp: // // int main(int argc, char **argv) // { // QCA::Initializer init; // QCoreApplication app(argc, argv); // return 0; // } // // however, the above code has the unfortunate side-effect of causing // qapp to deinit before qca, which can cause problems with any // plugins that have active objects (notably KeyStore). we'll use a // post routine to force qca to deinit first. qAddPostRoutine(deinit); }
void deinit() { QMutexLocker locker(global_mutex()); if(!global) return; --(global->refs); if(global->refs == 0) { // In order to maintain symmetry with the init() function, remove the // post routine from QCoreApplication. This is needed in case when the // QCA library is unloaded before QCoreApplication instance completes: // QCoreApplication d-tor would try to execute the deinit() function, // which would no longer be there. // Note that this function is documented only in Qt 5.3 and later, but // it has been present since ancient times with the same semantics. qRemovePostRoutine(deinit); delete global; global = 0; botan_deinit(); } }
void Choice::publish_traits_locked() { InputMutexGuard lock( global_mutex() ); publish_traits(); }