From 37486eb0c90b07450e3667127e9a86f3cf84fc86 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 28 May 2026 23:50:07 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=20=E5=A2=9E=E5=BC=BA=20OSC?= =?UTF-8?q?ommandRunner=20=E7=9A=84=E5=91=BD=E4=BB=A4=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86=E5=92=8C=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openflare_agent/internal/nginx/manager.go | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/openflare_agent/internal/nginx/manager.go b/openflare_agent/internal/nginx/manager.go index f79dd33d..b9f48464 100644 --- a/openflare_agent/internal/nginx/manager.go +++ b/openflare_agent/internal/nginx/manager.go @@ -45,9 +45,29 @@ type CommandRunner interface { type OSCommandRunner struct{} func (r *OSCommandRunner) Run(ctx context.Context, name string, args ...string) ([]byte, error) { + slog.Debug("OSCommandRunner starting command", "name", name, "args", args) + tmpFile, err := os.CreateTemp("", "openflare-cmd-*") + if err != nil { + slog.Error("OSCommandRunner failed to create temp file, falling back to CombinedOutput", "error", err) + cmd := exec.CommandContext(ctx, name, args...) + output, outErr := cmd.CombinedOutput() + slog.Debug("OSCommandRunner finished CombinedOutput", "name", name, "error", outErr) + return output, outErr + } + defer os.Remove(tmpFile.Name()) + cmd := exec.CommandContext(ctx, name, args...) - output, err := cmd.CombinedOutput() - return output, err + cmd.Stdout = tmpFile + cmd.Stderr = tmpFile + + slog.Debug("OSCommandRunner executing cmd.Run()", "name", name) + runErr := cmd.Run() + slog.Debug("OSCommandRunner cmd.Run() returned", "name", name, "error", runErr) + tmpFile.Close() + + output, _ := os.ReadFile(tmpFile.Name()) + slog.Debug("OSCommandRunner command complete", "name", name, "output_len", len(output)) + return output, runErr } type PathExecutor struct {