Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 22f3d3a

Browse files
committed
ssh: initialize libssh2
We should have been doing this, but it initializes itself upon first use, which works as long as nobody's doing concurrent network operations. Initialize it on our init to make sure it's not getting initialized concurrently.
1 parent 839bdb0 commit 22f3d3a

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/global.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "openssl_stream.h"
1313
#include "thread-utils.h"
1414
#include "git2/global.h"
15+
#include "transports/ssh.h"
1516

1617
#if defined(GIT_MSVC_CRTDBG)
1718
#include "win32/w32_stack.h"
@@ -56,7 +57,8 @@ static int init_common(void)
5657
/* Initialize any other subsystems that have global state */
5758
if ((ret = git_hash_global_init()) == 0 &&
5859
(ret = git_sysdir_global_init()) == 0 &&
59-
(ret = git_filter_global_init()) == 0)
60+
(ret = git_filter_global_init()) == 0 &&
61+
(ret = git_transport_ssh_global_init()) == 0)
6062
ret = git_openssl_stream_global_init();
6163

6264
GIT_MEMORY_BARRIER;

src/transports/ssh.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "smart.h"
1616
#include "cred.h"
1717
#include "socket_stream.h"
18+
#include "ssh.h"
1819

1920
#ifdef GIT_SSH
2021

@@ -876,3 +877,18 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p
876877
return -1;
877878
#endif
878879
}
880+
881+
int git_transport_ssh_global_init(void)
882+
{
883+
#ifdef GIT_SSH
884+
885+
libssh2_init(0);
886+
return 0;
887+
888+
#else
889+
890+
/* Nothing to initialize */
891+
return 0;
892+
893+
#endif
894+
}

src/transports/ssh.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_ssh_h__
8+
#define INCLUDE_ssh_h__
9+
10+
int git_transport_ssh_global_init(void);
11+
12+
#endif

0 commit comments

Comments
 (0)