2021-08-24 04:37:44 +08:00
|
|
|
//go:build !windows
|
2020-05-28 05:42:59 +08:00
|
|
|
|
2022-04-07 04:49:41 +08:00
|
|
|
package port_name
|
2020-05-28 05:42:59 +08:00
|
|
|
|
2022-05-24 21:22:56 +08:00
|
|
|
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`
|
2020-05-28 05:42:59 +08:00
|
|
|
func servicesPath() string {
|
2022-05-24 21:22:56 +08:00
|
|
|
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]
|
2020-05-28 05:42:59 +08:00
|
|
|
}
|