mirror of
https://github.com/kardianos/service.git
synced 2025-12-24 13:27:57 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user