1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

threads: support libgcrypt 1.6 hack

Not 100% satisfied of this patch, but the way libgcrypt handles
threading in 1.6 is not compatible with custom handlers. The
new code basicaly uses pthreads in every case. This will probably
not work on windows.
This commit is contained in:
Aris Adamantiadis
2014-01-08 16:58:49 +01:00
parent b617d7fa29
commit 57ef959aa3
3 changed files with 26 additions and 2 deletions

View File

@ -61,5 +61,6 @@ implement the following methods :
- mutex_destroy - mutex_destroy
- thread_id - thread_id
libgcrypt 1.6 and bigger backend does not support custom callback. Using anything else than pthreads (ssh_threads_get_pthread()) here will fail.
Good luck ! Good luck !
*/ */

View File

@ -801,6 +801,8 @@ struct ssh_threads_callbacks_struct {
* *
* @see ssh_threads_callbacks_struct * @see ssh_threads_callbacks_struct
* @see SSH_THREADS_PTHREAD * @see SSH_THREADS_PTHREAD
* @bug libgcrypt 1.6 and bigger backend does not support custom callback.
* Using anything else than pthreads here will fail.
*/ */
LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
*cb); *cb);

View File

@ -59,8 +59,28 @@ struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void) {
static struct ssh_threads_callbacks_struct *user_callbacks =&ssh_threads_noop; static struct ssh_threads_callbacks_struct *user_callbacks =&ssh_threads_noop;
#ifdef HAVE_LIBGCRYPT #ifdef HAVE_LIBGCRYPT
#if (GCRYPT_VERSION_NUMBER >= 0x010600)
/* libgcrypt >= 1.6 does not support custom callbacks */
GCRY_THREAD_OPTION_PTHREAD_IMPL;
/* Libgcrypt specific way of handling thread callbacks */ static int libgcrypt_thread_init(void){
if(user_callbacks == NULL)
return SSH_ERROR;
if(user_callbacks == &ssh_threads_noop)
return SSH_OK;
if (strcmp(user_callbacks->type, "threads_pthread") == 0){
gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
return SSH_OK;
} else {
/* not supported */
SSH_LOG(SSH_LOG_WARN, "Custom thread handlers not supported with libgcrypt >=1.6, using pthreads");
gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
return SSH_OK;
}
}
#else
/* Libgcrypt < 1.6 specific way of handling thread callbacks */
static struct gcry_thread_cbs gcrypt_threads_callbacks; static struct gcry_thread_cbs gcrypt_threads_callbacks;
@ -79,7 +99,8 @@ static int libgcrypt_thread_init(void){
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcrypt_threads_callbacks); gcry_control(GCRYCTL_SET_THREAD_CBS, &gcrypt_threads_callbacks);
return SSH_OK; return SSH_OK;
} }
#else #endif /* GCRYPT_VERSION_NUMBER */
#else /* HAVE_LIBGCRYPT */
/* Libcrypto specific stuff */ /* Libcrypto specific stuff */