Skip to content

Commit f167f4f

Browse files
authored
Merge pull request #44 from snorwin/sanitize-pid
strip non ascii from pids
2 parents 73cf82a + db57f92 commit f167f4f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

main.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
"sync"
1010
"syscall"
11+
"unicode"
1112

1213
"github.com/fsnotify/fsnotify"
1314
"github.com/snorwin/haproxy-reload-wrapper/pkg/exec"
@@ -183,14 +184,27 @@ func runInstance() {
183184
cmds = append(cmds, cmd)
184185
}
185186

187+
// pids returns the PID list as a space-separated string
186188
func pids() string {
187189
if len(cmds) == 0 {
188190
return ""
189191
}
190192

191193
out := make([]string, 0, len(cmds))
192194
for _, c := range cmds {
193-
out = append(out, strconv.Itoa(c.Process.Pid))
195+
out = append(out, stripCtrlChars(strconv.Itoa(c.Process.Pid)))
194196
}
195197
return strings.Join(out, " ")
196198
}
199+
200+
// stripCtrlChars returns a sanitized string
201+
// the PID read from the HAProxy socket includes a trailing control character,
202+
// usually the multi‑byte separator that HAProxy puts at the end of the Runtime API response
203+
func stripCtrlChars(s string) string {
204+
return strings.Map(func(r rune) rune {
205+
if unicode.IsControl(r) {
206+
return -1
207+
}
208+
return r
209+
}, s)
210+
}

0 commit comments

Comments
 (0)