Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely remove npth and all associated code. #14

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions legacy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,6 @@ target_link_libraries(assuan-test PRIVATE
GTest::GTest GTest::Main)
add_test(AssuanTest assuan-test COMMAND assuan-test test_xml_output --gtest_output=xml:assuan-test.xml)

# npth

add_library(npth
npth/src/npth.h
npth/src/npth.cpp
)
add_library(neopg::npth ALIAS npth)

target_include_directories(npth PRIVATE
npth/src
${CMAKE_BINARY_DIR}/.)
target_compile_definitions(npth PRIVATE
HAVE_CONFIG_H=1)

target_compile_options(npth PRIVATE -fpermissive
)

add_executable(npth-test
npth/tests/t-mutex.cpp
npth/tests/t-support.h
npth/tests/t-thread.cpp
npth/tests/npth-test.cpp)
target_include_directories(npth-test PRIVATE
npth/src
${CMAKE_BINARY_DIR}/.)
target_link_libraries(npth-test PRIVATE
npth
GTest::GTest GTest::Main)
add_test(nPthTest npth-test COMMAND npth-test test_xml_output --gtest_output=xml:npth-test.xml)

# libgcrypt

add_library(gcrypt
Expand Down
33 changes: 6 additions & 27 deletions legacy/gnupg/agent/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

#include <config.h>

#include <mutex>

#include <assert.h>
#include <npth.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -43,7 +44,7 @@ static const size_t ENCRYPTION_KEYSIZE = 128 / 8;
static Botan::SymmetricKey *encryption_handle;

/* A mutex used to serialize access to the cache. */
static npth_mutex_t cache_lock;
static std::mutex cache_lock;

struct secret_data_s {
int totallen; /* This includes the padding and space for AESWRAP. */
Expand All @@ -67,16 +68,6 @@ static ITEM thecache;
/* NULL or the last cache key stored by agent_store_cache_hit. */
static char *last_stored_cache_key;

/* This function must be called once to initialize this module. It
has to be done before a second thread is spawned. */
void initialize_module_cache(void) {
int err;

err = npth_mutex_init(&cache_lock, NULL);

if (err) log_fatal("error initializing cache module: %s\n", strerror(err));
}

void deinitialize_module_cache(void) {
delete encryption_handle;
encryption_handle = NULL;
Expand Down Expand Up @@ -211,8 +202,7 @@ void agent_flush_cache(void) {

if (DBG_CACHE) log_debug("agent_flush_cache\n");

res = npth_mutex_lock(&cache_lock);
if (res) log_fatal("failed to acquire cache mutex: %s\n", strerror(res));
std::lock_guard<std::mutex> lock(cache_lock);

for (r = thecache; r; r = r->next) {
if (r->pw) {
Expand All @@ -222,9 +212,6 @@ void agent_flush_cache(void) {
r->accessed = 0;
}
}

res = npth_mutex_unlock(&cache_lock);
if (res) log_fatal("failed to release cache mutex: %s\n", strerror(res));
}

/* Compare two cache modes. */
Expand All @@ -246,8 +233,7 @@ int agent_put_cache(const char *key, cache_mode_t cache_mode, const char *data,
ITEM r;
int res;

res = npth_mutex_lock(&cache_lock);
if (res) log_fatal("failed to acquire cache mutex: %s\n", strerror(res));
std::lock_guard<std::mutex> lock(cache_lock);

if (DBG_CACHE)
log_debug("agent_put_cache '%s' (mode %d) requested ttl=%d\n", key,
Expand Down Expand Up @@ -298,9 +284,6 @@ int agent_put_cache(const char *key, cache_mode_t cache_mode, const char *data,
}

out:
res = npth_mutex_unlock(&cache_lock);
if (res) log_fatal("failed to release cache mutex: %s\n", strerror(res));

return err;
}

Expand All @@ -316,8 +299,7 @@ char *agent_get_cache(const char *key, cache_mode_t cache_mode) {

if (cache_mode == CACHE_MODE_IGNORE) return NULL;

res = npth_mutex_lock(&cache_lock);
if (res) log_fatal("failed to acquire cache mutex: %s\n", strerror(res));
std::lock_guard<std::mutex> lock(cache_lock);

if (!key) {
key = last_stored_cache_key;
Expand Down Expand Up @@ -365,9 +347,6 @@ char *agent_get_cache(const char *key, cache_mode_t cache_mode) {
if (DBG_CACHE && value == NULL) log_debug("... miss\n");

out:
res = npth_mutex_unlock(&cache_lock);
if (res) log_fatal("failed to release cache mutex: %s\n", strerror(res));

return value;
}

Expand Down
Loading