mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-09-26 21:01:42 +08:00
Fix all linting errors found by cross-lint
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
This commit is contained in:
@@ -100,12 +100,16 @@ func main() {
|
||||
}
|
||||
|
||||
logrus.Debug("Setting up proxies")
|
||||
setupProxies(ctx, group, sources, dests, identities)
|
||||
err = setupProxies(ctx, group, sources, dests, identities)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error setting up proxies: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Wait for cmopletion (cancellation) or error
|
||||
// Wait for completion (cancellation) or error
|
||||
if err := group.Wait(); err != nil {
|
||||
logrus.Errorf("Error occured in execution group: " + err.Error())
|
||||
os.Exit(1)
|
||||
logrus.Errorf("Error occurred in execution group: " + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package fs
|
||||
|
@@ -30,7 +30,7 @@ func ListenNpipe(socketURI *url.URL) (net.Listener, error) {
|
||||
InputBufferSize: 65536,
|
||||
OutputBufferSize: 65536,
|
||||
}
|
||||
path := strings.Replace(socketURI.Path, "/", "\\", -1)
|
||||
path := strings.ReplaceAll(socketURI.Path, "/", "\\")
|
||||
|
||||
listener, err := winio.ListenPipe(path, &config)
|
||||
if err != nil {
|
||||
|
@@ -47,7 +47,9 @@ var _ = Describe("connectivity", func() {
|
||||
It("proxies over a windows pipe", func() {
|
||||
err := startProxy()
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
defer stopProxy(false)
|
||||
defer func() {
|
||||
Expect(stopProxy(false)).ShouldNot(HaveOccurred())
|
||||
}()
|
||||
httpClient := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
@@ -71,19 +73,18 @@ var _ = Describe("connectivity", func() {
|
||||
g.Expect(string(reply)).To(Equal("pong"))
|
||||
|
||||
}).Should(Succeed())
|
||||
|
||||
err = stopProxy(true)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
|
||||
It("windows event logs were created", func() {
|
||||
cmd := exec.Command("powershell", "-Command", "&{Get-WinEvent -ProviderName \".NET Runtime\" -MaxEvents 10 | Where-Object -Property Message -Match \"test:\"}")
|
||||
reader, err := cmd.StdoutPipe()
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
cmd.Start()
|
||||
err = cmd.Start()
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
output, err := io.ReadAll(reader)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
cmd.Wait()
|
||||
err = cmd.Wait()
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(strings.Contains(string(output), `[info ] test: Listening on: \\.\pipe\fake_docker_engine`)).Should(BeTrue())
|
||||
Expect(strings.Contains(string(output), `[debug] test: Socket forward established`)).Should(BeTrue())
|
||||
})
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package e2e
|
||||
@@ -42,7 +43,7 @@ func startMockServer() {
|
||||
}
|
||||
sshConfig.AddHostKey(key)
|
||||
|
||||
listener, err := net.Listen("tcp", ":2134")
|
||||
listener, err := net.Listen("tcp", "localhost:2134")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -83,7 +84,7 @@ func stopMockServer() {
|
||||
}
|
||||
|
||||
func handleRequests(reqs <-chan *ssh.Request) {
|
||||
for _ = range reqs {
|
||||
for range reqs {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,14 +92,20 @@ func handleChannels(chans <-chan ssh.NewChannel) {
|
||||
directMsg := streamLocalDirect{}
|
||||
for newChannel := range chans {
|
||||
if t := newChannel.ChannelType(); t != "direct-streamlocal@openssh.com" {
|
||||
newChannel.Reject(ssh.UnknownChannelType, fmt.Sprintf("unknown channel type: %s", t))
|
||||
err := newChannel.Reject(ssh.UnknownChannelType, fmt.Sprintf("unknown channel type: %s", t))
|
||||
if err != nil {
|
||||
logrus.Errorf("could not reject channel: %s", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if err := ssh.Unmarshal(newChannel.ExtraData(), &directMsg); err != nil {
|
||||
logrus.Errorf("could not direct-streamlocal data: %s", err)
|
||||
|
||||
newChannel.Reject(ssh.Prohibited, "invalid format")
|
||||
err = newChannel.Reject(ssh.Prohibited, "invalid format")
|
||||
if err != nil {
|
||||
logrus.Errorf("could not reject channel: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -124,7 +131,13 @@ func handleChannels(chans <-chan ssh.NewChannel) {
|
||||
resp.StatusCode = 404
|
||||
resp.ContentLength = 0
|
||||
}
|
||||
resp.Write(channel)
|
||||
channel.CloseWrite()
|
||||
err = resp.Write(channel)
|
||||
if err != nil {
|
||||
logrus.Errorf("could not write response: %s", err)
|
||||
}
|
||||
err = channel.CloseWrite()
|
||||
if err != nil {
|
||||
logrus.Errorf("could not close write: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package e2e
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -64,14 +66,20 @@ func readTid() (uint32, uint32, error) {
|
||||
}
|
||||
|
||||
var pid, tid uint32
|
||||
fmt.Sscanf(string(contents), "%d:%d", &pid, &tid)
|
||||
_, err = fmt.Sscanf(string(contents), "%d:%d", &pid, &tid)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return pid, tid, nil
|
||||
}
|
||||
|
||||
func sendQuit(tid uint32) {
|
||||
user32 := syscall.NewLazyDLL("user32.dll")
|
||||
postMessage := user32.NewProc("PostThreadMessageW")
|
||||
postMessage.Call(uintptr(tid), WM_QUIT, 0, 0)
|
||||
_, _, err := postMessage.Call(uintptr(tid), WM_QUIT, 0, 0)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error posting quit message: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func stopProxy(noKill bool) error {
|
||||
|
Reference in New Issue
Block a user