]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
sync: abort if stdin/stdout is a terminal
authorSimon Ruderich <simon@ruderich.org>
Tue, 6 Apr 2021 09:50:58 +0000 (11:50 +0200)
committerSimon Ruderich <simon@ruderich.org>
Wed, 7 Apr 2021 05:48:14 +0000 (07:48 +0200)
Notify the user that is probably not what they intended to do.

cmd/safcm-remote/main.go

index bf5159f0c89e9fa3d7c1dd904ff9a8476a4ba4ef..e9ce1cd0ccac627e6573bc5b07c040166cb4be65 100644 (file)
@@ -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