~afrantzis/mir/fix-1462088-cursor-api-through-nested-test

« back to all changes in this revision

Viewing changes to src/protobuf/google_protobuf_guard.cpp

  • Committer: Tarmac
  • Author(s): Daniel van Vugt
  • Date: 2015-06-25 11:58:49 UTC
  • mfrom: (2690.2.3 fix-1391976)
  • Revision ID: tarmac-20150625115849-2yjh2z8qxnyta05q
Fix^H^H^H Work around protobuf reload issues so that it's always safe
to un/reload libmirprotobuf multiple times. (LP: #1391976)

Technically a proper fix will come from libprotobuf itself but this way
we don't need to wait for that. Fixes: https://bugs.launchpad.net/bugs/1391976.

Approved by PS Jenkins bot, Robert Carr, Kevin DuBois, Alexandros Frantzis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <google/protobuf/descriptor.h>
22
22
#include <mutex>
 
23
#include <dlfcn.h>
23
24
 
24
25
namespace mir
25
26
{
30
31
 
31
32
void init_google_protobuf()
32
33
{
 
34
    // Leak libmirprotobuf.so.X
 
35
    // This will stop it getting unloaded/reloaded and work around LP: #1391976
 
36
    Dl_info self;
 
37
    if (dladdr(reinterpret_cast<void*>(&init_google_protobuf), &self))
 
38
    {
 
39
        dlopen(self.dli_fname, RTLD_LAZY | RTLD_NODELETE);
 
40
    }
 
41
 
33
42
    GOOGLE_PROTOBUF_VERIFY_VERSION;
34
43
}
35
44