From 0512f043cf9daf14f8e24aab85307cad967493a9 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 10 Nov 2023 19:17:56 -0700 Subject: [PATCH] cleanup logging a bit --- cmds.go | 7 ++++++- main.go | 9 ++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmds.go b/cmds.go index 5b7bbe6..034d4ee 100644 --- a/cmds.go +++ b/cmds.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/exec" + "strings" ) type Command struct { @@ -19,8 +20,11 @@ type Command struct { func (c *Command) Run(fp string) bool { cmd := &exec.Cmd{} if len(c.Args) == 0 { - cmd = exec.Command(c.Path, fmt.Sprintf(c.MsgFormat, fp)) + msg := fmt.Sprintf(c.MsgFormat, fp) + log.Printf("running %q\n", fmt.Sprintf("%s %s", c.Path, msg)) + cmd = exec.Command(c.Path, msg) } else { + log.Printf("running %q\n", fmt.Sprintf("%s %s", c.Path, strings.Join(c.Args, " "))) cmd = exec.Command(c.Path, c.Args...) } @@ -39,6 +43,7 @@ func (c *Command) Run(fp string) bool { if exit.ExitCode() == c.AllowExitCode { return true } + return false } return true diff --git a/main.go b/main.go index 855058b..b1f83d3 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,8 @@ func main() { if err != nil { log.Fatalln(err) } + + cmds := LoadCommands(*cmdList) tagent := Traygent{ listener: l, addChan: make(chan ssh.PublicKey), @@ -57,26 +59,21 @@ func main() { } }() - cmds := LoadCommands(*cmdList) - for { select { case added := <-tagent.addChan: fp := ssh.FingerprintSHA256(added) - log.Printf("NOTICE: added %q\n", fp) c := cmds.Get("added") if c != nil { c.Run(fp) } case rm := <-tagent.rmChan: - log.Printf("NOTICE: removed %q\n", rm) c := cmds.Get("removed") if c != nil { c.Run(rm) } case pub := <-tagent.sigReq: fp := ssh.FingerprintSHA256(pub) - log.Printf("NOTICE: access request for: %q?\n", fp) c := cmds.Get("sign") if c != nil { if c.Run(fp) { @@ -84,8 +81,6 @@ func main() { } else { go func() { tagent.sigResp <- false }() } - } else { - panic("nope") } } }