Skip to content
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

Fix remote logs #7660

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions pkg/api/handlers/compat/containers_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {

var frame strings.Builder
header := make([]byte, 8)

writeHeader := true
// Docker does not write stream headers iff the container has a tty.
if !utils.IsLibpodRequest(r) {
inspectData, err := ctnr.Inspect(false)
if err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "Failed to obtain logs for Container '%s'", name))
return
}
writeHeader = !inspectData.Config.Tty
}

for line := range logChannel {
if _, found := r.URL.Query()["until"]; found {
if line.Time.After(until) {
Expand Down Expand Up @@ -138,10 +150,13 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
}
frame.WriteString(line.Msg)

binary.BigEndian.PutUint32(header[4:], uint32(frame.Len()))
if _, err := w.Write(header[0:8]); err != nil {
log.Errorf("unable to write log output header: %q", err)
if writeHeader {
binary.BigEndian.PutUint32(header[4:], uint32(frame.Len()))
if _, err := w.Write(header[0:8]); err != nil {
log.Errorf("unable to write log output header: %q", err)
}
}

if _, err := io.WriteString(w, frame.String()); err != nil {
log.Errorf("unable to write frame string: %q", err)
}
Expand Down