From 6d50719513bcd5994526232facf4f289b9e0e75a Mon Sep 17 00:00:00 2001
From: zhong-jiawei-1 <zhongjiawei1@huawei.com>
Date: Mon, 24 Oct 2022 20:44:25 +0800
Subject: [PATCH] runc:unified use of logpipe

---
 runc-1.1.3/libcontainer/container_linux.go    |  1 -
 .../libcontainer/standard_init_linux.go       | 30 +------------------
 runc-1.1.3/main.go                            | 25 ----------------
 3 files changed, 1 insertion(+), 55 deletions(-)

diff --git a/runc-1.1.3/libcontainer/container_linux.go b/runc-1.1.3/libcontainer/container_linux.go
index 5ef5a9a..10890c1 100644
--- a/runc-1.1.3/libcontainer/container_linux.go
+++ b/runc-1.1.3/libcontainer/container_linux.go
@@ -355,7 +355,6 @@ func (c *linuxContainer) start(process *Process) (retErr error) {
 	}
 
 	if err := parent.start(); err != nil {
-		printCgroupInfo(c.config.Cgroups.Path)
 		return fmt.Errorf("unable to start container process: %w", err)
 	}
 
diff --git a/runc-1.1.3/libcontainer/standard_init_linux.go b/runc-1.1.3/libcontainer/standard_init_linux.go
index 8a60501..99e7003 100644
--- a/runc-1.1.3/libcontainer/standard_init_linux.go
+++ b/runc-1.1.3/libcontainer/standard_init_linux.go
@@ -276,34 +276,6 @@ func (l *linuxStandardInit) Init() error {
 		return err
 	}
 
-	if err := system.Exec(name, l.config.Args[0:], os.Environ()); err != nil {
-		printCgroupInfo("")
-		return err
-	}
-	return nil
-}
-
-func printCgroupInfo(path string) {
-	cgroupRoot := "/sys/fs/cgroup"
-	infoFileList := []string{
-		"/proc/meminfo",
-		"/sys/fs/cgroup/memory/memory.stat",
-		filepath.Join(cgroupRoot, "files", path, "files.limit"),
-		filepath.Join(cgroupRoot, "files", path, "files.usage"),
-		filepath.Join(cgroupRoot, "pids", path, "pids.max"),
-		filepath.Join(cgroupRoot, "pids", path, "pids.current"),
-		filepath.Join(cgroupRoot, "memory", path, "memory.usage_in_bytes"),
-		filepath.Join(cgroupRoot, "memory", path, "memory.limit_in_bytes"),
-		filepath.Join(cgroupRoot, "memory", path, "memory.stat"),
-		filepath.Join(cgroupRoot, "cpu", path, "cpu.stat"),
-	}
-	for _, file := range infoFileList {
-		printFileContent(file)
-	}
-}
-
-func printFileContent(path string) {
-	output, err := ioutil.ReadFile(path)
-	logrus.Infof("content read from %s: %s, err: %v", path, string(output), err)
+	return system.Exec(name, l.config.Args[0:], os.Environ())
 }
 
diff --git a/runc-1.1.3/main.go b/runc-1.1.3/main.go
index 6e9101a..e624347 100644
--- a/runc-1.1.3/main.go
+++ b/runc-1.1.3/main.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"encoding/json"
 	"errors"
 	"fmt"
 	"io"
@@ -11,13 +10,11 @@ import (
 	"runtime"
 	"strconv"
 	"strings"
-	"time"
 
 	"github.com/opencontainers/runc/libcontainer/seccomp"
 	"github.com/opencontainers/runtime-spec/specs-go"
 
 	"github.com/sirupsen/logrus"
-	logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
 	"github.com/urfave/cli"
 )
 
@@ -219,12 +216,6 @@ func configLogrus(context *cli.Context) error {
 			return err
 		}
 		logrus.SetOutput(f)
-		hook, serr := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO|syslog.LOG_USER, "docker-runc")
-		if serr != nil {
-			logToFile(f, "error", fmt.Sprintf("Leo: new syslog hook get %s", serr))
-		} else {
-			logrus.AddHook(hook)
-		}
 	}
 	if logLevel := context.GlobalString("log-level"); logLevel != "" {
 		lvl, err := logrus.ParseLevel(logLevel)
@@ -241,19 +232,3 @@ func configLogrus(context *cli.Context) error {
 	return nil
 }
 
-func logToFile(f io.Writer, level string, msg string) {
-	var (
-		log struct {
-			Level string
-			Msg   string
-			Time  time.Time
-		}
-	)
-	log.Level = level
-	log.Msg = msg
-	log.Time = time.Now()
-	s, err := json.Marshal(log)
-	if err != nil {
-		fmt.Fprint(f, string(s))
-	}
-}
-- 
2.30.0

