diff options
author | Martin Willi <martin@revosec.ch> | 2012-07-11 17:08:30 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-07-13 13:23:29 +0200 |
commit | b46776aea159df93264ca7df02a2169a0e57e258 (patch) | |
tree | 0e6dbc1e1708a9d4187c91773abaa43f42454d79 | |
parent | 893c3a4ead7e3fcf523b6ab83a4dd61fa7b54c9f (diff) | |
download | strongswan-b46776aea159df93264ca7df02a2169a0e57e258.tar.bz2 strongswan-b46776aea159df93264ca7df02a2169a0e57e258.tar.xz |
Add an external method to disable leak detective temporarly
-rw-r--r-- | src/libstrongswan/utils/leak_detective.c | 30 | ||||
-rw-r--r-- | src/libstrongswan/utils/leak_detective.h | 8 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c index 81524b6e7..edf743b11 100644 --- a/src/libstrongswan/utils/leak_detective.c +++ b/src/libstrongswan/utils/leak_detective.c @@ -397,6 +397,35 @@ METHOD(leak_detective_t, report, void, } } +METHOD(leak_detective_t, set_state, bool, + private_leak_detective_t *this, bool enable) +{ + static struct sched_param oldparams; + static int oldpolicy; + struct sched_param params; + pthread_t thread_id; + + if (enable == installed) + { + return installed; + } + thread_id = pthread_self(); + if (enable) + { + install_hooks(); + pthread_setschedparam(thread_id, oldpolicy, &oldparams); + } + else + { + pthread_getschedparam(thread_id, &oldpolicy, &oldparams); + params.__sched_priority = sched_get_priority_max(SCHED_FIFO); + pthread_setschedparam(thread_id, SCHED_FIFO, ¶ms); + uninstall_hooks(); + } + installed = enable; + return !installed; +} + METHOD(leak_detective_t, usage, void, private_leak_detective_t *this, FILE *out) { @@ -620,6 +649,7 @@ leak_detective_t *leak_detective_create() .public = { .report = _report, .usage = _usage, + .set_state = _set_state, .destroy = _destroy, }, ); diff --git a/src/libstrongswan/utils/leak_detective.h b/src/libstrongswan/utils/leak_detective.h index 8c80d2532..55d7e44d9 100644 --- a/src/libstrongswan/utils/leak_detective.h +++ b/src/libstrongswan/utils/leak_detective.h @@ -50,6 +50,14 @@ struct leak_detective_t { void (*usage)(leak_detective_t *this, FILE *out); /** + * Enable/disable leak detective hooks. + * + * @param TRUE to enable, FALSE to disable + * @return state active before calling set_state + */ + bool (*set_state)(leak_detective_t *this, bool enabled); + + /** * Destroy a leak_detective instance. */ void (*destroy)(leak_detective_t *this); |