-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2627 fix "some of" golangci-lint problems #2641
Changes from all commits
c3b31e7
a3bd52b
2735709
56b1aa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,119 +61,142 @@ terminals: | |
) | ||
|
||
func bail(err error) { | ||
fmt.Fprintf(os.Stderr, "[recvtty] fatal error: %v\n", err) | ||
_, _ = fmt.Fprintf(os.Stderr, "[recvtty] fatal error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
func handleSingle(path string, noStdin bool) error { | ||
func handleSingle(path string, noStdin bool) (retErr error) { | ||
// Open a socket. | ||
ln, err := net.Listen("unix", path) | ||
if err != nil { | ||
return err | ||
ln, retErr := net.Listen("unix", path) | ||
if retErr != nil { | ||
return retErr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You did't have to change any of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IOW this can stay |
||
} | ||
defer ln.Close() | ||
defer func() { | ||
_ = ln.Close() | ||
}() | ||
|
||
// We only accept a single connection, since we can only really have | ||
// one reader for os.Stdin. Plus this is all a PoC. | ||
conn, err := ln.Accept() | ||
if err != nil { | ||
return err | ||
conn, retErr := ln.Accept() | ||
if retErr != nil { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
defer conn.Close() | ||
defer func() { | ||
_ = conn.Close() | ||
}() | ||
|
||
// Close ln, to allow for other instances to take over. | ||
ln.Close() | ||
_ = ln.Close() | ||
|
||
// Get the fd of the connection. | ||
unixconn, ok := conn.(*net.UnixConn) | ||
if !ok { | ||
return fmt.Errorf("failed to cast to unixconn") | ||
} | ||
|
||
socket, err := unixconn.File() | ||
if err != nil { | ||
return err | ||
socket, retErr := unixconn.File() | ||
if retErr != nil { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
defer socket.Close() | ||
defer func() { | ||
_ = socket.Close() | ||
}() | ||
|
||
// Get the master file descriptor from runC. | ||
master, err := utils.RecvFd(socket) | ||
if err != nil { | ||
return err | ||
master, retErr := utils.RecvFd(socket) | ||
if retErr != nil { | ||
return | ||
} | ||
c, err := console.ConsoleFromFile(master) | ||
if err != nil { | ||
return err | ||
c, retErr := console.ConsoleFromFile(master) | ||
if retErr != nil { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
if err := console.ClearONLCR(c.Fd()); err != nil { | ||
return err | ||
} | ||
|
||
// Copy from our stdio to the master fd. | ||
quitChan := make(chan struct{}) | ||
errChan := make(chan error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK it seems that in this case a single channel is enough, there is no need to have two. |
||
go func() { | ||
io.Copy(os.Stdout, c) | ||
_, err := io.Copy(os.Stdout, c) | ||
if err != nil { | ||
errChan <- err | ||
} | ||
quitChan <- struct{}{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IOW this could be simple _, err := io.Copy(os.Stdout, c)
chan <- err and the code that's receiving this will check for nil |
||
}() | ||
if !noStdin { | ||
go func() { | ||
io.Copy(c, os.Stdin) | ||
_, err := io.Copy(c, os.Stdin) | ||
if err != nil { | ||
errChan <- err | ||
} | ||
quitChan <- struct{}{} | ||
}() | ||
} | ||
|
||
// Only close the master fd once we've stopped copying. | ||
<-quitChan | ||
c.Close() | ||
return nil | ||
select { | ||
case retErr = <-errChan: | ||
return retErr | ||
case <-quitChan: | ||
retErr = c.Close() | ||
return retErr | ||
} | ||
} | ||
|
||
func handleNull(path string) error { | ||
func handleNull(path string) (retErr error) { | ||
// Open a socket. | ||
ln, err := net.Listen("unix", path) | ||
if err != nil { | ||
return err | ||
ln, retErr := net.Listen("unix", path) | ||
if retErr != nil { | ||
return retErr | ||
} | ||
defer ln.Close() | ||
defer func() { | ||
_ = ln.Close() | ||
}() | ||
|
||
// As opposed to handleSingle we accept as many connections as we get, but | ||
// we don't interact with Stdin at all (and we copy stdout to /dev/null). | ||
for { | ||
conn, err := ln.Accept() | ||
if err != nil { | ||
return err | ||
conn, retErr := ln.Accept() | ||
if retErr != nil { | ||
return retErr | ||
} | ||
go func(conn net.Conn) { | ||
// Don't leave references lying around. | ||
defer conn.Close() | ||
defer func() { | ||
_ = conn.Close() | ||
}() | ||
|
||
// Get the fd of the connection. | ||
unixconn, ok := conn.(*net.UnixConn) | ||
if !ok { | ||
return | ||
} | ||
|
||
socket, err := unixconn.File() | ||
if err != nil { | ||
socket, retErr := unixconn.File() | ||
if retErr != nil { | ||
return | ||
} | ||
defer socket.Close() | ||
defer func() { | ||
_ = socket.Close() | ||
}() | ||
|
||
// Get the master file descriptor from runC. | ||
master, err := utils.RecvFd(socket) | ||
if err != nil { | ||
master, retErr := utils.RecvFd(socket) | ||
if retErr != nil { | ||
return | ||
} | ||
|
||
// Just do a dumb copy to /dev/null. | ||
devnull, err := os.OpenFile("/dev/null", os.O_RDWR, 0) | ||
if err != nil { | ||
devnull, retErr := os.OpenFile("/dev/null", os.O_RDWR, 0) | ||
if retErr != nil { | ||
// TODO: Handle this nicely. | ||
return | ||
} | ||
|
||
io.Copy(devnull, master) | ||
devnull.Close() | ||
_, _ = io.Copy(devnull, master) | ||
_ = devnull.Close() | ||
}(conn) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not inline with what the commit message says. Please split your commits carefully.