Merge 7b9c13ac16
into 924821e4bf
This commit is contained in:
commit
e2e4107ee3
4 changed files with 33 additions and 25 deletions
|
@ -1,5 +1,8 @@
|
|||
package main
|
||||
|
||||
// #include "../../conmon/config.h"
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
@ -40,9 +43,9 @@ func validateConfig(config *server.Config) error {
|
|||
|
||||
}
|
||||
|
||||
// This needs to match the read buffer size in conmon
|
||||
if config.LogSizeMax >= 0 && config.LogSizeMax < 8192 {
|
||||
return fmt.Errorf("log size max should be negative or >= 8192")
|
||||
bufSize := int64(C.BUF_SIZE)
|
||||
if config.LogSizeMax >= 0 && config.LogSizeMax < bufSize {
|
||||
return fmt.Errorf("log size max should be negative or >= %d", bufSize)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
18
conmon/config.h
Normal file
18
conmon/config.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#if !defined(CONFIG_H)
|
||||
#define CONFIG_H
|
||||
|
||||
#define BUF_SIZE 8192
|
||||
#define STDIO_BUF_SIZE 8192
|
||||
|
||||
/* stdpipe_t represents one of the std pipes (or NONE). */
|
||||
typedef enum {
|
||||
NO_PIPE,
|
||||
STDIN_PIPE, /* unused */
|
||||
STDOUT_PIPE,
|
||||
STDERR_PIPE,
|
||||
} stdpipe_t;
|
||||
|
||||
|
||||
#endif // CONFIG_H
|
|
@ -26,6 +26,7 @@
|
|||
#include <glib-unix.h>
|
||||
|
||||
#include "cmsg.h"
|
||||
#include "config.h"
|
||||
|
||||
#define pexit(fmt, ...) \
|
||||
do { \
|
||||
|
@ -91,7 +92,6 @@ static inline void strv_cleanup(char ***strv)
|
|||
#define _cleanup_gstring_ _cleanup_(gstring_free_cleanup)
|
||||
#define _cleanup_strv_ _cleanup_(strv_cleanup)
|
||||
|
||||
#define BUF_SIZE 8192
|
||||
#define CMD_SIZE 1024
|
||||
#define MAX_EVENTS 10
|
||||
|
||||
|
@ -263,15 +263,6 @@ int set_k8s_timestamp(char *buf, ssize_t buflen, const char *pipename)
|
|||
return err;
|
||||
}
|
||||
|
||||
/* stdpipe_t represents one of the std pipes (or NONE).
|
||||
* Sync with const in container_attach.go */
|
||||
typedef enum {
|
||||
NO_PIPE,
|
||||
STDIN_PIPE, /* unused */
|
||||
STDOUT_PIPE,
|
||||
STDERR_PIPE,
|
||||
} stdpipe_t;
|
||||
|
||||
const char *stdpipe_name(stdpipe_t pipe)
|
||||
{
|
||||
switch (pipe) {
|
||||
|
@ -571,11 +562,10 @@ static gboolean tty_hup_timeout_cb (G_GNUC_UNUSED gpointer user_data)
|
|||
|
||||
static bool read_stdio(int fd, stdpipe_t pipe, bool *eof)
|
||||
{
|
||||
#define STDIO_BUF_SIZE 8192 /* Sync with redirectResponseToOutputStreams() */
|
||||
/* We use one extra byte at the start, which we don't read into, instead
|
||||
we use that for marking the pipe when we write to the attached socket */
|
||||
char real_buf[STDIO_BUF_SIZE + 1];
|
||||
char *buf = real_buf + 1;
|
||||
char *buf = real_buf + 1;
|
||||
ssize_t num_read = 0;
|
||||
|
||||
if (eof)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package server
|
||||
|
||||
// #include "../conmon/config.h"
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -18,13 +21,6 @@ import (
|
|||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
)
|
||||
|
||||
/* Sync with stdpipe_t in conmon.c */
|
||||
const (
|
||||
AttachPipeStdin = 1
|
||||
AttachPipeStdout = 2
|
||||
AttachPipeStderr = 3
|
||||
)
|
||||
|
||||
// Attach prepares a streaming endpoint to attach to a running container.
|
||||
func (s *Server) Attach(ctx context.Context, req *pb.AttachRequest) (resp *pb.AttachResponse, err error) {
|
||||
const operation = "attach"
|
||||
|
@ -113,16 +109,17 @@ func (ss streamService) Attach(containerID string, inputStream io.Reader, output
|
|||
}
|
||||
|
||||
func redirectResponseToOutputStreams(outputStream, errorStream io.Writer, conn io.Reader) error {
|
||||
stdioBufSize := int(C.STDIO_BUF_SIZE)
|
||||
var err error
|
||||
buf := make([]byte, 8192+1) /* Sync with conmon STDIO_BUF_SIZE */
|
||||
buf := make([]byte, stdioBufSize+1)
|
||||
|
||||
for {
|
||||
nr, er := conn.Read(buf)
|
||||
if nr > 0 {
|
||||
var dst io.Writer
|
||||
if buf[0] == AttachPipeStdout {
|
||||
if buf[0] == byte(C.STDOUT_PIPE) {
|
||||
dst = outputStream
|
||||
} else if buf[0] == AttachPipeStderr {
|
||||
} else if buf[0] == byte(C.STDERR_PIPE) {
|
||||
dst = errorStream
|
||||
} else {
|
||||
logrus.Infof("Got unexpected attach type %+d", buf[0])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue