From: Simon Ruderich Date: Tue, 6 Apr 2021 09:50:58 +0000 (+0200) Subject: sync: abort if stdin/stdout is a terminal X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=commitdiff_plain;h=ad55f8167bc4e36b71e9d71d8c01443861a989c5 sync: abort if stdin/stdout is a terminal Notify the user that is probably not what they intended to do. --- 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