We need to allow crypto to be set up and torn down before a fork. Count
the init/shutdown cycles to make that safe.
Signed-off-by: Sage Weil <sage@redhat.com>
_set_gid(0),
_set_uid_string(),
_set_gid_string(),
- _crypto_inited(false),
+ _crypto_inited(0),
_service_thread(NULL),
_log_obs(NULL),
_admin_socket(NULL),
delete _crypto_none;
delete _crypto_aes;
- if (_crypto_inited)
- ceph::crypto::shutdown(g_code_env == CODE_ENVIRONMENT_LIBRARY);
+ if (_crypto_inited > 0) {
+ assert(_crypto_inited == 1); // or else someone explicitly did
+ // init but not shutdown
+ shutdown_crypto();
+ }
}
void CephContext::put() {
void CephContext::init_crypto()
{
- if (!_crypto_inited) {
+ if (_crypto_inited++ == 0) {
ceph::crypto::init(this);
- _crypto_inited = true;
+ }
+}
+
+void CephContext::shutdown_crypto()
+{
+ if (--_crypto_inited == 0) {
+ ceph::crypto::shutdown(g_code_env == CODE_ENVIRONMENT_LIBRARY);
}
}
/* init ceph::crypto */
void init_crypto();
+ /// shutdown crypto (should match init_crypto calls)
+ void shutdown_crypto();
+
/* Start the Ceph Context's service thread */
void start_service_thread();
std::string _set_uid_string;
std::string _set_gid_string;
- bool _crypto_inited;
+ int _crypto_inited;
/* libcommon service thread.
* SIGHUP wakes this thread, which then reopens logfiles */