]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm-remote/main.go
Improve and add comments
[safcm/safcm.git] / cmd / safcm-remote / main.go
index bf5159f0c89e9fa3d7c1dd904ff9a8476a4ba4ef..ab0bfae917286283e59bcb16af1c2ffabe15432a 100644 (file)
@@ -1,4 +1,4 @@
-// Helper copied to the remote hosts to run commands and deploy configuration
+// Helper copied to the remote host to run commands and deploy configuration
 
 // Copyright (C) 2021  Simon Ruderich
 //
@@ -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