diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index b71a58599..c2fd63665 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -36,6 +36,8 @@ const time_t STORE_KEY_TIMEOUT = 1 * 60 * 60; //store key is call around every hour +void cleanupZombies(int numkill); // function to cleanup zombies under OSX. + //#define GPG_DEBUG 1 static AuthGPGimpl *instance_gpg = NULL; @@ -894,6 +896,8 @@ bool AuthGPGimpl::DoOwnSignature(const void *data, unsigned int datalen, void *b std::cerr << "Error create Sig" << std::endl; } + cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation) + /* move string data to gpgmeData */ gpgme_set_armor (CTX, 0); @@ -995,7 +999,7 @@ bool AuthGPGimpl::VerifySignature(const void *data, int datalen, const void *sig std::cerr << "Error create Sig" << std::endl; } - /* move string data to gpgmeData */ + cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation) gpgme_set_armor (CTX, 0); @@ -1083,6 +1087,8 @@ bool AuthGPGimpl::GeneratePGPCertificate(std::string name, std::string email, gpgme_genkey_result_t result; gpg_error_t ERR; + cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation) + if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_genkey(CTX, setKeyPairParams(true, 2048, name, "generated by Retroshare", email, \ passwd).c_str(), NULL, NULL))) { ProcessPGPmeError(ERR); @@ -1207,6 +1213,9 @@ bool AuthGPGimpl::decryptText(gpgme_data_t CIPHER, gpgme_data_t PLAIN) { RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/ gpgme_set_armor (CTX, 1); gpg_error_t ERR; + + cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation) + if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_decrypt (CTX, CIPHER, PLAIN))) { ProcessPGPmeError(ERR); @@ -1223,6 +1232,10 @@ bool AuthGPGimpl::encryptText(gpgme_data_t PLAIN, gpgme_data_t CIPHER) { gpgme_key_t keys[2] = {mOwnGpgCert.key, NULL}; gpgme_set_armor (CTX, 1); gpg_error_t ERR; + + cleanupZombies(2); // cleanup zombies under OSX. (Called before gpgme operation) + + if (GPG_ERR_NO_ERROR != (ERR = gpgme_op_encrypt(CTX, keys, *flags, PLAIN, CIPHER))) { ProcessPGPmeError(ERR); @@ -2395,3 +2408,48 @@ bool AuthGPGimpl::addService(AuthGPGService *service) services.push_back(service); return true; } + + +/***************************** HACK to Cleanup OSX Zombies *****************************/ + + +#include + +void cleanupZombies(int numkill) +{ + +#ifdef __APPLE__ + + pid_t wpid = -1; // any child. + int stat_loc = 0; + int options = WNOHANG ; + + //std::cerr << "cleanupZombies() checking for dead children"; + //std::cerr << std::endl; + + int i; + for(i = 0; i < numkill; i++) + { + pid_t childpid = waitpid(wpid, &stat_loc, options); + + if (childpid > 0) + { + std::cerr << "cleanupZombies() Found stopped child with pid: " << childpid; + std::cerr << std::endl; + } + else + { + //std::cerr << "cleanupZombies() No Zombies around!"; + //std::cerr << std::endl; + break; + } + } + + std::cerr << "cleanupZombies() Killed " << i << " zombies"; + std::cerr << std::endl; + +#endif + + return; +} + diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 8c4d13511..7aa20e5ad 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -121,7 +121,7 @@ macx { CONFIG += version_detail_bash_script LIBS += ../../libretroshare/src/lib/libretroshare.a - LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error + LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan LIBS += ../../../miniupnpc-1.0/libminiupnpc.a LIBS += -framework CoreFoundation