From fd33ae55b9bf02b39ab2db0bbc8585c8ca5ea1d4 Mon Sep 17 00:00:00 2001 From: Huang Zhaobin <1159326901@qq.com> Date: Fri, 17 Jan 2025 15:38:00 +0800 Subject: [PATCH] fix(config): correct the truncation of process name(comm name) Previously dae truncate the process names in pname configs to 16 bytes Now we truncate the name to 15 bytes because the length of the comm name of processes in linux is 15 bytes. This makes `pname(systemd-resolved)` works the same as `pname(systemd-resolve)` Closes #736, #474 --- component/routing/function_parser.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/component/routing/function_parser.go b/component/routing/function_parser.go index c125f1026..86786aef6 100644 --- a/component/routing/function_parser.go +++ b/component/routing/function_parser.go @@ -108,8 +108,8 @@ func ProcessNameParserFactory(callback func(f *config_parser.Function, procNames return func(log *logrus.Logger, f *config_parser.Function, key string, paramValueGroup []string, overrideOutbound *Outbound) (err error) { var procNames [][consts.TaskCommLen]byte for _, v := range paramValueGroup { - if len([]byte(v)) > consts.TaskCommLen { - log.Infof(`pname routing: trim "%v" to "%v" because it is too long.`, v, string([]byte(v)[:consts.TaskCommLen])) + if len([]byte(v)) > consts.TaskCommLen - 1 { + log.Infof(`pname routing: trim "%v" to "%v" because it is too long.`, v, string([]byte(v)[:consts.TaskCommLen-1])) } procNames = append(procNames, toProcessName(v)) } @@ -134,6 +134,6 @@ func parsePrefixes(values []string) (cidrs []netip.Prefix, err error) { func toProcessName(processName string) (procName [consts.TaskCommLen]byte) { n := []byte(processName) - copy(procName[:], n) + copy(procName[:consts.TaskCommLen-1], n) return procName }