From ad55f8167bc4e36b71e9d71d8c01443861a989c5 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 6 Apr 2021 11:50:58 +0200 Subject: [PATCH] sync: abort if stdin/stdout is a terminal Notify the user that is probably not what they intended to do. --- cmd/safcm-remote/main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/safcm-remote/main.go b/cmd/safcm-remote/main.go index bf5159f..e9ce1cd 100644 --- a/cmd/safcm-remote/main.go +++ b/cmd/safcm-remote/main.go @@ -22,6 +22,8 @@ import ( "log" "os" + "golang.org/x/term" + "ruderich.org/simon/safcm" "ruderich.org/simon/safcm/cmd/safcm-remote/ainsl" "ruderich.org/simon/safcm/cmd/safcm-remote/info" @@ -62,6 +64,12 @@ func main() { } func mainLoop() error { + if term.IsTerminal(int(os.Stdin.Fd())) || + term.IsTerminal(int(os.Stdout.Fd())) { + return fmt.Errorf("sync should only be called from `safcm` " + + "(redirect stdin/stdout to circumvent this check)") + } + conn := safcm.NewGobConn(os.Stdin, os.Stdout) var logLevel safcm.LogLevel -- 2.45.2