aix issue 242: improved test, if process runs as child of srcmstr (#302)

Co-authored-by: xca1075 <Christoph.Buescher@atruvia.de>
This commit is contained in:
chbuescher
2021-11-11 18:20:41 +01:00
committed by GitHub
parent b9d1d5b727
commit 6fe2824ee8

View File

@@ -44,20 +44,17 @@ func (aixSystem) New(i Interface, c *Config) (Service, error) {
return s, nil
}
func getPidOfSvcMaster() int {
pat := regexp.MustCompile(`\s+root\s+(\d+)\s+\d+\s+\d+\s+\w+\s+\d+\s+\S+\s+[0-9:]+\s+/usr/sbin/srcmstr`)
cmd := exec.Command("ps", "-ef")
func getArgsFromPid(pid int) string {
cmd := exec.Command("ps", "-o", "args", "-p", strconv.Itoa(pid))
var out bytes.Buffer
cmd.Stdout = &out
pid := 0
if err := cmd.Run(); err == nil {
matches := pat.FindAllStringSubmatch(out.String(), -1)
for _, match := range matches {
pid, _ = strconv.Atoi(match[1])
break
lines := strings.Split(out.String(), "\n")
if len(lines) > 1 {
return strings.TrimSpace(lines[1])
}
}
return pid
return ""
}
func init() {
@@ -75,8 +72,8 @@ func init() {
}
func isInteractive() (bool, error) {
// The PPid of a service process should match PID of srcmstr.
return os.Getppid() != getPidOfSvcMaster(), nil
// The parent process of a service process should be srcmstr.
return getArgsFromPid(os.Getppid()) != "/usr/sbin/srcmstr", nil
}
type aixService struct {