mirror of
https://github.com/containers/podman.git
synced 2025-10-17 11:14:40 +08:00
Merge pull request #26609 from Luap99/bindings-fixes
pkg/bindings/containers: some attach/logs handling fixes
This commit is contained in:
@ -219,7 +219,7 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri
|
|||||||
// Read multiplexed channels and write to appropriate stream
|
// Read multiplexed channels and write to appropriate stream
|
||||||
fd, l, err := DemuxHeader(socket, buffer)
|
fd, l, err := DemuxHeader(socket, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -232,19 +232,19 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri
|
|||||||
switch fd {
|
switch fd {
|
||||||
case 0:
|
case 0:
|
||||||
if isSet.stdout {
|
if isSet.stdout {
|
||||||
if _, err := stdout.Write(frame[0:l]); err != nil {
|
if _, err := stdout.Write(frame); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
if isSet.stdout {
|
if isSet.stdout {
|
||||||
if _, err := stdout.Write(frame[0:l]); err != nil {
|
if _, err := stdout.Write(frame); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if isSet.stderr {
|
if isSet.stderr {
|
||||||
if _, err := stderr.Write(frame[0:l]); err != nil {
|
if _, err := stderr.Write(frame); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,14 +259,10 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri
|
|||||||
|
|
||||||
// DemuxHeader reads header for stream from server multiplexed stdin/stdout/stderr/2nd error channel
|
// DemuxHeader reads header for stream from server multiplexed stdin/stdout/stderr/2nd error channel
|
||||||
func DemuxHeader(r io.Reader, buffer []byte) (fd, sz int, err error) {
|
func DemuxHeader(r io.Reader, buffer []byte) (fd, sz int, err error) {
|
||||||
n, err := io.ReadFull(r, buffer[0:8])
|
_, err = io.ReadFull(r, buffer[0:8])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n < 8 {
|
|
||||||
err = io.ErrUnexpectedEOF
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = int(buffer[0])
|
fd = int(buffer[0])
|
||||||
if fd < 0 || fd > 3 {
|
if fd < 0 || fd > 3 {
|
||||||
@ -284,14 +280,10 @@ func DemuxFrame(r io.Reader, buffer []byte, length int) (frame []byte, err error
|
|||||||
buffer = append(buffer, make([]byte, length-len(buffer)+1)...)
|
buffer = append(buffer, make([]byte, length-len(buffer)+1)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
n, err := io.ReadFull(r, buffer[0:length])
|
_, err = io.ReadFull(r, buffer[0:length])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if n < length {
|
|
||||||
err = io.ErrUnexpectedEOF
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer[0:length], nil
|
return buffer[0:length], nil
|
||||||
}
|
}
|
||||||
@ -548,7 +540,7 @@ func ExecStartAndAttach(ctx context.Context, sessionID string, options *ExecStar
|
|||||||
// Read multiplexed channels and write to appropriate stream
|
// Read multiplexed channels and write to appropriate stream
|
||||||
fd, l, err := DemuxHeader(socket, buffer)
|
fd, l, err := DemuxHeader(socket, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -563,19 +555,19 @@ func ExecStartAndAttach(ctx context.Context, sessionID string, options *ExecStar
|
|||||||
if options.GetAttachInput() {
|
if options.GetAttachInput() {
|
||||||
// Write STDIN to STDOUT (echoing characters
|
// Write STDIN to STDOUT (echoing characters
|
||||||
// typed by another attach session)
|
// typed by another attach session)
|
||||||
if _, err := options.GetOutputStream().Write(frame[0:l]); err != nil {
|
if _, err := options.GetOutputStream().Write(frame); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
if options.GetAttachOutput() {
|
if options.GetAttachOutput() {
|
||||||
if _, err := options.GetOutputStream().Write(frame[0:l]); err != nil {
|
if _, err := options.GetOutputStream().Write(frame); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if options.GetAttachError() {
|
if options.GetAttachError() {
|
||||||
if _, err := options.GetErrorStream().Write(frame[0:l]); err != nil {
|
if _, err := options.GetErrorStream().Write(frame); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func Logs(ctx context.Context, nameOrID string, options *LogOptions, stdoutChan,
|
|||||||
for {
|
for {
|
||||||
fd, l, err := DemuxHeader(response.Body, buffer)
|
fd, l, err := DemuxHeader(response.Body, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -383,6 +383,11 @@ var _ = Describe("Podman containers ", func() {
|
|||||||
o = strings.TrimSpace(o)
|
o = strings.TrimSpace(o)
|
||||||
_, err = time.Parse(time.RFC1123Z, o)
|
_, err = time.Parse(time.RFC1123Z, o)
|
||||||
Expect(err).ShouldNot(HaveOccurred())
|
Expect(err).ShouldNot(HaveOccurred())
|
||||||
|
|
||||||
|
// drain the line channel and make sure there are no more log lines
|
||||||
|
for l := range stdoutChan {
|
||||||
|
Fail("container logs returned more than one line: " + l)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman top", func() {
|
It("podman top", func() {
|
||||||
|
@ -250,7 +250,7 @@ var _ = Describe("Podman update", func() {
|
|||||||
testCtr := "test-ctr-name"
|
testCtr := "test-ctr-name"
|
||||||
|
|
||||||
// Test that the variable is not set.
|
// Test that the variable is not set.
|
||||||
ctr1 := podmanTest.Podman([]string{"run", "-t", "--name", testCtr, ALPINE, "printenv", "FOO"})
|
ctr1 := podmanTest.Podman([]string{"run", "--name", testCtr, ALPINE, "printenv", "FOO"})
|
||||||
ctr1.WaitWithDefaultTimeout()
|
ctr1.WaitWithDefaultTimeout()
|
||||||
Expect(ctr1).Should(Exit(1))
|
Expect(ctr1).Should(Exit(1))
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ var _ = Describe("Podman update", func() {
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
env := session.OutputToString()
|
env := session.OutputToString()
|
||||||
Expect(env).To(ContainSubstring("BAR"))
|
Expect(env).To(Equal("BAR"))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"inspect", testCtr, "--format", "{{.Config.Env}}"})
|
session = podmanTest.Podman([]string{"inspect", testCtr, "--format", "{{.Config.Env}}"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
@ -281,7 +281,7 @@ var _ = Describe("Podman update", func() {
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
env = session.OutputToString()
|
env = session.OutputToString()
|
||||||
Expect(env).To(ContainSubstring("RAB"))
|
Expect(env).To(Equal("RAB"))
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"inspect", testCtr, "--format", "{{.Config.Env}}"})
|
session = podmanTest.Podman([]string{"inspect", testCtr, "--format", "{{.Config.Env}}"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user