Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit72d9ec0

Browse files
authored
fix: detect JetBrains running on local ipv6 (#11676)
1 parent552e9fe commit72d9ec0

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

‎agent/agentssh/portinspection_supported.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package agentssh
44

55
import (
6+
"errors"
67
"fmt"
78
"os"
89

@@ -11,24 +12,37 @@ import (
1112
)
1213

1314
funcgetListeningPortProcessCmdline(portuint32) (string,error) {
14-
tabs,err:=netstat.TCPSocks(func(s*netstat.SockTabEntry)bool {
15+
acceptFn:=func(s*netstat.SockTabEntry)bool {
1516
returns.LocalAddr!=nil&&uint32(s.LocalAddr.Port)==port
16-
})
17-
iferr!=nil {
18-
return"",xerrors.Errorf("inspect port %d: %w",port,err)
1917
}
20-
iflen(tabs)==0 {
21-
return"",nil
18+
tabs4,err4:=netstat.TCPSocks(acceptFn)
19+
tabs6,err6:=netstat.TCP6Socks(acceptFn)
20+
21+
// In the common case, we want to check ipv4 listening addresses. If this
22+
// fails, we should return an error. We also need to check ipv6. The
23+
// assumption is, if we have an err4, and 0 ipv6 addresses listed, then we are
24+
// interested in the err4 (and vice versa). So return both errors (at least 1
25+
// is non-nil) if the other list is empty.
26+
if (err4!=nil&&len(tabs6)==0)|| (err6!=nil&&len(tabs4)==0) {
27+
return"",xerrors.Errorf("inspect port %d: %w",port,errors.Join(err4,err6))
2228
}
2329

24-
// Defensive check.
25-
iftabs[0].Process==nil {
30+
varproc*netstat.Process
31+
iflen(tabs4)>0 {
32+
proc=tabs4[0].Process
33+
}elseiflen(tabs6)>0 {
34+
proc=tabs6[0].Process
35+
}
36+
ifproc==nil {
37+
// Either nothing is listening on this port or we were unable to read the
38+
// process details (permission issues reading /proc/$pid/* potentially).
39+
// Or, perhaps /proc/net/tcp{,6} is not listing the port for some reason.
2640
return"",nil
2741
}
2842

2943
// The process name provided by go-netstat does not include the full command
3044
// line so grab that instead.
31-
pid:=tabs[0].Process.Pid
45+
pid:=proc.Pid
3246
data,err:=os.ReadFile(fmt.Sprintf("/proc/%d/cmdline",pid))
3347
iferr!=nil {
3448
return"",xerrors.Errorf("read /proc/%d/cmdline: %w",pid,err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp