Example #1
0
func waitPortBinding(watchedPort string, strictBinding bool) {
	for {
		p := procfs.Self()

		pids := []int{}

		if strictBinding {
			descendants, err := p.Descendants()
			if err != nil {
				log.Error(err)
				break
			}

			for _, p := range descendants {
				pids = append(pids, p.Pid)
			}
			log.Debug(pids)
		}

		binderPid, err := port.IsPortBound(watchedPort, pids)
		if err != nil {
			log.Error(err)
			break
		}
		log.Debug(binderPid)
		if binderPid != -1 {
			log.Debugf("port %s binded by pid %d (used strict check: %v)", watchedPort, binderPid, strictBinding)
			processStateChanged(notifier.StatusRunning)
			break
		}
		time.Sleep(200 * time.Millisecond)
	}
}
Example #2
0
// Send the given signal to every processes except for the PID 1
func signalAllDescendants(sig syscall.Signal) error {
	self := procfs.Self()
	pses, err := self.Descendants()
	if err != nil {
		return err
	}
	for _, ps := range pses {
		err = syscall.Kill(ps.Pid, sig)
	}
	return err
}