diff --git a/service_aix.go b/service_aix.go index 5710b96..58f356d 100644 --- a/service_aix.go +++ b/service_aix.go @@ -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 {