From a840006e58e984c0903554e3951d6f89ad6777a0 Mon Sep 17 00:00:00 2001 From: Heiko Schlittermann Date: Tue, 24 May 2022 15:22:56 +0200 Subject: [PATCH] fix: search services file in /etc/services and fall back to /usr/etc/services (#11179) --- .../port_name/services_path_notwindows.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/processors/port_name/services_path_notwindows.go b/plugins/processors/port_name/services_path_notwindows.go index 08ce0ebba..54e85b41c 100644 --- a/plugins/processors/port_name/services_path_notwindows.go +++ b/plugins/processors/port_name/services_path_notwindows.go @@ -3,6 +3,23 @@ package port_name +import ( + "os" +) + +// servicesPath tries to find the `services` file at the common +// place(s) on most systems and returns its path. If it can't +// find anything, it returns the common default `/etc/services` func servicesPath() string { - return "/etc/services" + var files = []string{ + "/etc/services", + "/usr/etc/services", // fallback on OpenSuSE + } + + for i := range files { + if _, err := os.Stat(files[i]); err == nil { + return files[i] + } + } + return files[0] }