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