diff options
author | Anders Björklund <anders.bjorklund.2@volvocars.com> | 2020-02-18 14:08:35 +0100 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2020-04-15 06:51:22 +0000 |
commit | 8e0fe1920eee959ad14225ad2327793371be05d1 (patch) | |
tree | db8cb7e6cf088cdcd5fdd411c75ea62ccc51f27c /git_command.py | |
parent | d086467012e1970f44f27b67b4296a2a6fb097d5 (diff) | |
download | git-repo-8e0fe1920eee959ad14225ad2327793371be05d1.tar.gz |
Use hash for ControlPath instead of full variables
The generated socket path can be too long, if your FQDN is very long...
Typical error message from ssh client:
unix_listener: path "/tmp/ssh-fqduawon/master-USER@HOST:PORT.qfCZ51OAZgTzVLbg" too long for Unix domain socket
Use a hashed version instead, to keep within the socket file path limit.
This requires OpenSSH_6.7p1, or later.
Change-Id: Ia4bb9ae8aac6c4ee31d5a458f917f3753f40001b
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255632
Reviewed-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Anders Björklund <anders.bjorklund.2@volvocars.com>
Diffstat (limited to 'git_command.py')
-rw-r--r-- | git_command.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/git_command.py b/git_command.py index a2782151..1cb8f1aa 100644 --- a/git_command.py +++ b/git_command.py | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | from __future__ import print_function | 17 | from __future__ import print_function |
18 | import os | 18 | import os |
19 | import re | ||
19 | import sys | 20 | import sys |
20 | import subprocess | 21 | import subprocess |
21 | import tempfile | 22 | import tempfile |
@@ -47,6 +48,35 @@ LAST_CWD = None | |||
47 | _ssh_proxy_path = None | 48 | _ssh_proxy_path = None |
48 | _ssh_sock_path = None | 49 | _ssh_sock_path = None |
49 | _ssh_clients = [] | 50 | _ssh_clients = [] |
51 | _ssh_version = None | ||
52 | |||
53 | |||
54 | def _run_ssh_version(): | ||
55 | """run ssh -V to display the version number""" | ||
56 | return subprocess.check_output(['ssh', '-V'], stderr=subprocess.STDOUT).decode() | ||
57 | |||
58 | |||
59 | def _parse_ssh_version(ver_str=None): | ||
60 | """parse a ssh version string into a tuple""" | ||
61 | if ver_str is None: | ||
62 | ver_str = _run_ssh_version() | ||
63 | m = re.match(r'^OpenSSH_([0-9.]+)(p[0-9]+)?\s', ver_str) | ||
64 | if m: | ||
65 | return tuple(int(x) for x in m.group(1).split('.')) | ||
66 | else: | ||
67 | return () | ||
68 | |||
69 | |||
70 | def ssh_version(): | ||
71 | """return ssh version as a tuple""" | ||
72 | global _ssh_version | ||
73 | if _ssh_version is None: | ||
74 | try: | ||
75 | _ssh_version = _parse_ssh_version() | ||
76 | except subprocess.CalledProcessError: | ||
77 | print('fatal: unable to detect ssh version', file=sys.stderr) | ||
78 | sys.exit(1) | ||
79 | return _ssh_version | ||
50 | 80 | ||
51 | 81 | ||
52 | def ssh_sock(create=True): | 82 | def ssh_sock(create=True): |
@@ -57,9 +87,13 @@ def ssh_sock(create=True): | |||
57 | tmp_dir = '/tmp' | 87 | tmp_dir = '/tmp' |
58 | if not os.path.exists(tmp_dir): | 88 | if not os.path.exists(tmp_dir): |
59 | tmp_dir = tempfile.gettempdir() | 89 | tmp_dir = tempfile.gettempdir() |
90 | if ssh_version() < (6, 7): | ||
91 | tokens = '%r@%h:%p' | ||
92 | else: | ||
93 | tokens = '%C' # hash of %l%h%p%r | ||
60 | _ssh_sock_path = os.path.join( | 94 | _ssh_sock_path = os.path.join( |
61 | tempfile.mkdtemp('', 'ssh-', tmp_dir), | 95 | tempfile.mkdtemp('', 'ssh-', tmp_dir), |
62 | 'master-%r@%h:%p') | 96 | 'master-' + tokens) |
63 | return _ssh_sock_path | 97 | return _ssh_sock_path |
64 | 98 | ||
65 | 99 | ||