Bound notification delivery and expansion
This commit is contained in:
committed by
Brandon McGinty
parent
4497d41077
commit
d64e5125dd
@@ -47,8 +47,10 @@ func do_list_devices() {
|
||||
show_devs("Inputs:", idevs)
|
||||
}
|
||||
|
||||
const notificationQueueSize = 32
|
||||
|
||||
func setup_notify_runner(notify_command string) chan []string {
|
||||
t := make(chan []string)
|
||||
t := make(chan []string, notificationQueueSize)
|
||||
var do_nothing = false
|
||||
var err error
|
||||
if err != nil {
|
||||
@@ -57,23 +59,28 @@ func setup_notify_runner(notify_command string) chan []string {
|
||||
do_nothing = true
|
||||
}
|
||||
go func(events chan []string, cmd_template string, dummy bool) {
|
||||
for {
|
||||
event := <-events
|
||||
for event := range events {
|
||||
if !dummy {
|
||||
t := string(cmd_template)
|
||||
t = strings.ReplaceAll(t, "%event", shellescape.Quote(event[0]))
|
||||
t = strings.ReplaceAll(t, "%who", shellescape.Quote(event[1]))
|
||||
t = strings.ReplaceAll(t, "%what", shellescape.Quote(event[2]))
|
||||
cmd := "/bin/sh"
|
||||
args := []string{"-c", t}
|
||||
args := []string{"-c", expandNotification(cmd_template, event)}
|
||||
x := exec.Command(cmd, args...)
|
||||
x.Run()
|
||||
} //if we actually have a command to run
|
||||
} //for
|
||||
}
|
||||
}
|
||||
}(t, notify_command, do_nothing)
|
||||
return t
|
||||
}
|
||||
|
||||
// expandNotification replaces placeholders in one pass so text supplied for
|
||||
// one field cannot cause another placeholder to be expanded recursively.
|
||||
func expandNotification(template string, event []string) string {
|
||||
return strings.NewReplacer(
|
||||
"%event", shellescape.Quote(event[0]),
|
||||
"%who", shellescape.Quote(event[1]),
|
||||
"%what", shellescape.Quote(event[2]),
|
||||
).Replace(template)
|
||||
}
|
||||
|
||||
func setup_fifo(fn string) (chan string, error) {
|
||||
t := make(chan string)
|
||||
if fn == "" {
|
||||
|
||||
Reference in New Issue
Block a user