From 8318951e312a44311ca20e83007628dfdca34e26 Mon Sep 17 00:00:00 2001 From: zhongjiawei Date: Mon, 7 Nov 2022 19:44:59 +0800 Subject: [PATCH] runc: runc log forward to syslog --- git-commit | 2 +- ...0029-runc-runc-log-forward-to-syslog.patch | 88 +++++++++++++++++++ runc.spec | 8 +- series.conf | 1 + 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 patch/0029-runc-runc-log-forward-to-syslog.patch diff --git a/git-commit b/git-commit index fce7565..f28100d 100644 --- a/git-commit +++ b/git-commit @@ -1 +1 @@ -43d228d300f9de4c4071f6e8adb7205271383185 +caecfec06584770e48dcfba57461f7b89e08babe diff --git a/patch/0029-runc-runc-log-forward-to-syslog.patch b/patch/0029-runc-runc-log-forward-to-syslog.patch new file mode 100644 index 0000000..acf6201 --- /dev/null +++ b/patch/0029-runc-runc-log-forward-to-syslog.patch @@ -0,0 +1,88 @@ +From 0ee4b516f4e39ccef4b893a678b01095acbe6ad0 Mon Sep 17 00:00:00 2001 +From: zhongjiawei +Date: Mon, 7 Nov 2022 18:56:11 +0800 +Subject: [PATCH] runc:runc log forward to syslog + +--- + runc-1.1.3/main.go | 27 ++++++++++++++++++- + .../sirupsen/logrus/hooks/syslog/syslog.go | 2 +- + 2 files changed, 27 insertions(+), 2 deletions(-) + +diff --git a/runc-1.1.3/main.go b/runc-1.1.3/main.go +index e52a2ea..381681e 100644 +--- a/runc-1.1.3/main.go ++++ b/runc-1.1.3/main.go +@@ -1,19 +1,23 @@ + package main + + import ( ++ "encoding/json" + "errors" + "fmt" + "io" ++ "log/syslog" + "os" + "path/filepath" + "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" + ) + +@@ -215,6 +219,12 @@ 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("new syslog hook get %s", serr)) ++ } else { ++ logrus.AddHook(hook) ++ } + } + if logLevel := context.GlobalString("log-level"); logLevel != "" { + lvl, err := logrus.ParseLevel(logLevel) +@@ -230,4 +240,19 @@ 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)) ++ } ++} +diff --git a/runc-1.1.3/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go b/runc-1.1.3/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go +index b6fa374..430f646 100644 +--- a/runc-1.1.3/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go ++++ b/runc-1.1.3/vendor/github.com/sirupsen/logrus/hooks/syslog/syslog.go +@@ -2,7 +2,7 @@ package logrus_syslog + + import ( + "fmt" +- "github.com/Sirupsen/logrus" ++ "github.com/sirupsen/logrus" + "log/syslog" + "os" + ) +-- +2.30.0 + diff --git a/runc.spec b/runc.spec index 9948da1..52fccad 100644 --- a/runc.spec +++ b/runc.spec @@ -3,7 +3,7 @@ Name: docker-runc Version: 1.1.3 -Release: 5 +Release: 6 Summary: runc is a CLI tool for spawning and running containers according to the OCI specification. License: ASL 2.0 @@ -54,6 +54,12 @@ install -p -m 755 runc $RPM_BUILD_ROOT/%{_bindir}/runc %{_bindir}/runc %changelog +* Mon Nov 7 2022 zhongjiawei - 1.1.3-6 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:runc log forward to syslog + * Fri Nov 4 2022 zhongjiawei - 1.1.3-5 - Type:bugfix - CVE:NA diff --git a/series.conf b/series.conf index 42547ce..0a542b9 100644 --- a/series.conf +++ b/series.conf @@ -26,3 +26,4 @@ patch/0025-runc-support-set-cpuset.prefer_cpus-using-cpuset-cpu.patch patch/0026-runc-add-DT-for-cpuset.preferred_cpus-setting.patch patch/0027-runc-modify-runc-Makefile.patch patch/0028-runc-cgroup-apply-method-modify.patch +patch/0029-runc-runc-log-forward-to-syslog.patch