]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm-remote/sync/commands.go
remote: show group/trigger in verbose log for commands
[safcm/safcm.git] / cmd / safcm-remote / sync / commands.go
index 84a318d79668b8e43118d9981e5d7736db3f766c..5a3c59c1d1d4c156396992733c1ed27131fe2364 100644 (file)
@@ -31,7 +31,7 @@ func (s *Sync) syncCommands() error {
        // Run triggered commands first
        for _, path := range s.triggers {
                for _, x := range s.req.Files[path].TriggerCommands {
-                       err := s.syncCommand(x, path)
+                       err := s.syncCommand(x, "", path)
                        if err != nil {
                                return err
                        }
@@ -40,7 +40,7 @@ func (s *Sync) syncCommands() error {
        // Regular commands afterwards so they can react on triggers if
        // necessary
        for _, x := range s.req.Commands {
-               err := s.syncCommand(x.Cmd, "")
+               err := s.syncCommand(x.Cmd, x.OrigGroup, "")
                if err != nil {
                        return err
                }
@@ -48,7 +48,7 @@ func (s *Sync) syncCommands() error {
        return nil
 }
 
-func (s *Sync) syncCommand(command string, trigger string) error {
+func (s *Sync) syncCommand(command, group, trigger string) error {
        s.resp.CommandChanges = append(s.resp.CommandChanges,
                safcm.CommandChange{
                        Command: command,
@@ -59,12 +59,20 @@ func (s *Sync) syncCommand(command string, trigger string) error {
        }
        change := &s.resp.CommandChanges[len(s.resp.CommandChanges)-1]
 
+       var info string
+       if trigger != "" {
+               info = fmt.Sprintf("%q", trigger)
+       } else if group != "" {
+               info = group
+       }
+
        cmd := exec.Command("/bin/sh", "-c", command)
        cmd.Env = safcmEnviroment(s.req.Groups)
        // Cannot use cmd.CombinedOutputCmd() because we need another log
        // level (here the command is the actual change and not a side effect)
        // and different error handling.
-       s.log.Verbosef("commands: running %s", run.QuoteForDebug(cmd))
+       s.log.Verbosef("commands: running %s (%s)",
+               run.QuoteForDebug(cmd), info)
        out, err := s.cmd.Runner.CombinedOutput(cmd)
        if len(out) > 0 {
                s.log.Debug2f("commands: command output:\n%s", out)