From 5c84089dabc1b8bf4749c2dec018869073b4a925 Mon Sep 17 00:00:00 2001 From: kwb0523 Date: Mon, 25 Sep 2023 21:50:36 +0800 Subject: [PATCH] sync some changes from 23.09 branch 1.fix mda output with newline symbol 2.fix miss va_end after va_start in log file --- oncn-mda/cli_src/func/log.c | 4 +++- pkg/bpf/bpf.go | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/oncn-mda/cli_src/func/log.c b/oncn-mda/cli_src/func/log.c index 9bd8361..970a973 100644 --- a/oncn-mda/cli_src/func/log.c +++ b/oncn-mda/cli_src/func/log.c @@ -38,8 +38,10 @@ void ma_log(enum LOG_LEVEL level, const char* format, ...) va_list ap; va_start(ap, format); char fmt_str[MAX_FMT_STR_LENGTH] = {0}; - if (vsnprintf_s(fmt_str, sizeof(fmt_str), sizeof(fmt_str) - 1, format, ap) == -1) + if (vsnprintf_s(fmt_str, sizeof(fmt_str), sizeof(fmt_str) - 1, format, ap) == -1) { + va_end(ap); return; + } va_end(ap); (void)fprintf(stderr, "%s", fmt_str); diff --git a/pkg/bpf/bpf.go b/pkg/bpf/bpf.go index 900d5e0..7ea2ae5 100644 --- a/pkg/bpf/bpf.go +++ b/pkg/bpf/bpf.go @@ -21,6 +21,7 @@ package bpf import ( "fmt" "os/exec" + "strings" "github.com/cilium/ebpf" "github.com/cilium/ebpf/rlimit" @@ -71,11 +72,11 @@ func StartMda() error { cmd := exec.Command("mdacore", "enable") output, err := cmd.CombinedOutput() if err != nil { - log.Error(string(output)) + log.Error(strings.Replace(string(output), "\n", " ", -1)) return err } - log.Info(string(output)) + log.Info(strings.Replace(string(output), "\n", " ", -1)) return nil } @@ -105,11 +106,11 @@ func StopMda() error { cmd := exec.Command("mdacore", "disable") output, err := cmd.CombinedOutput() if err != nil { - log.Error(string(output)) + log.Error(strings.Replace(string(output), "\n", " ", -1)) return err } - log.Info(string(output)) + log.Info(strings.Replace(string(output), "\n", " ", -1)) return nil } -- Gitee