From 949dbf730370b5d73ce833446a019d2e6a948c3d Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Mon, 4 Jul 2022 12:59:57 -0400 Subject: [PATCH] Fix up stderr for all external dumpcap routines Termshark uses a custom approach to capturing, preferring dumpcap but then launching tshark if dumpcap fails (e.g. on extcap interfaces). This fixes up stderr for the non-Linux builds so that if capture fails altogether, the stderr printed out on the terminal is more easily digestible. --- cmd/termshark/termshark.go | 2 +- system/dumpcapext.go | 2 +- system/dumpcapext_arm64.go | 8 ++++---- system/dumpcapext_darwin.go | 8 ++++---- system/dumpcapext_windows.go | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 901cda8..69a496e 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -744,7 +744,7 @@ func cmain() int { } fmt.Fprintf(os.Stderr, "Standard error stream from %s:\n", cbin) - fmt.Fprintf(os.Stderr, "\n%s\n", stderr.String()) + fmt.Fprintf(os.Stderr, "------\n%s\n------\n", stderr.String()) } if runtime.GOOS == "linux" && os.Geteuid() != 0 { fmt.Fprintf(os.Stderr, "You might need: sudo setcap cap_net_raw,cap_net_admin+eip %s\n", termshark.PrivilegedBin()) diff --git a/system/dumpcapext.go b/system/dumpcapext.go index 516863f..da04353 100644 --- a/system/dumpcapext.go +++ b/system/dumpcapext.go @@ -61,7 +61,7 @@ func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { fmt.Fprintf(os.Stderr, "Starting termshark's custom live capture procedure.\n") dumpcapCmd := exec.Command(dumpcapBin, args...) - fmt.Fprintf(os.Stderr, "First, trying dumpcap command %v\n", dumpcapCmd) + fmt.Fprintf(os.Stderr, "Trying dumpcap command %v\n", dumpcapCmd) dumpcapCmd.Stdin = os.Stdin dumpcapCmd.Stdout = os.Stdout dumpcapCmd.Stderr = os.Stderr diff --git a/system/dumpcapext_arm64.go b/system/dumpcapext_arm64.go index f441d22..618ec81 100644 --- a/system/dumpcapext_arm64.go +++ b/system/dumpcapext_arm64.go @@ -8,11 +8,10 @@ package system import ( + "fmt" "os" "os/exec" "syscall" - - log "github.com/sirupsen/logrus" ) //====================================================================== @@ -26,7 +25,8 @@ func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { var err error dumpcapCmd := exec.Command(dumpcapBin, args...) - log.Infof("Starting dumpcap command %v", dumpcapCmd) + fmt.Fprintf(os.Stderr, "Starting termshark's custom live capture procedure.\n") + fmt.Fprintf(os.Stderr, "Trying dumpcap command %v\n", dumpcapCmd) dumpcapCmd.Stdin = os.Stdin dumpcapCmd.Stdout = os.Stdout dumpcapCmd.Stderr = os.Stderr @@ -34,7 +34,7 @@ func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { var tshark string tshark, err = exec.LookPath(tsharkBin) if err == nil { - log.Infof("Retrying with dumpcap command %v", append([]string{tshark}, args...)) + fmt.Fprintf(os.Stderr, "Retrying with dumpcap command %v\n", append([]string{tshark}, args...)) err = syscall.Exec(tshark, append([]string{tshark}, args...), os.Environ()) } } diff --git a/system/dumpcapext_darwin.go b/system/dumpcapext_darwin.go index e188d66..4ff80f7 100644 --- a/system/dumpcapext_darwin.go +++ b/system/dumpcapext_darwin.go @@ -5,11 +5,10 @@ package system import ( + "fmt" "os" "os/exec" "syscall" - - log "github.com/sirupsen/logrus" ) //====================================================================== @@ -23,7 +22,8 @@ func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { var err error dumpcapCmd := exec.Command(dumpcapBin, args...) - log.Infof("Starting dumpcap command %v", dumpcapCmd) + fmt.Fprintf(os.Stderr, "Starting termshark's custom live capture procedure.\n") + fmt.Fprintf(os.Stderr, "Trying dumpcap command %v\n", dumpcapCmd) dumpcapCmd.Stdin = os.Stdin dumpcapCmd.Stdout = os.Stdout dumpcapCmd.Stderr = os.Stderr @@ -31,7 +31,7 @@ func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { var tshark string tshark, err = exec.LookPath(tsharkBin) if err == nil { - log.Infof("Retrying with dumpcap command %v", append([]string{tshark}, args...)) + fmt.Fprintf(os.Stderr, "Retrying with dumpcap command %v\n", append([]string{tshark}, args...)) err = syscall.Exec(tshark, append([]string{tshark}, args...), os.Environ()) } } diff --git a/system/dumpcapext_windows.go b/system/dumpcapext_windows.go index d5dc26a..5d249b5 100644 --- a/system/dumpcapext_windows.go +++ b/system/dumpcapext_windows.go @@ -5,10 +5,9 @@ package system import ( + "fmt" "os" "os/exec" - - log "github.com/sirupsen/logrus" ) //====================================================================== @@ -20,7 +19,8 @@ import ( // tshark supports extcap interfaces. func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { dumpcapCmd := exec.Command(dumpcapBin, args...) - log.Infof("Starting dumpcap command %v", dumpcapCmd) + fmt.Fprintf(os.Stderr, "Starting termshark's custom live capture procedure.\n") + fmt.Fprintf(os.Stderr, "Trying dumpcap command %v\n", dumpcapCmd) dumpcapCmd.Stdin = os.Stdin dumpcapCmd.Stdout = os.Stdout dumpcapCmd.Stderr = os.Stderr @@ -29,7 +29,7 @@ func DumpcapExt(dumpcapBin string, tsharkBin string, args ...string) error { } tsharkCmd := exec.Command(tsharkBin, args...) - log.Infof("Retrying with dumpcap command %v", tsharkCmd) + fmt.Fprintf(os.Stderr, "Retrying with dumpcap command %v\n", tsharkCmd) tsharkCmd.Stdin = os.Stdin tsharkCmd.Stdout = os.Stdout tsharkCmd.Stderr = os.Stderr