Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon.Search() doesn't actually confirm if a PID is alive on UNIX* systems #73

Open
stew3254 opened this issue Feb 27, 2021 · 1 comment

Comments

@stew3254
Copy link
Contributor

I noticed that the search function doesn't actually test whether a process is alive or not. According to the docs for os.FindProcess(pid) this will never be nil on Unix systems even when a process doesn't exist.

On Unix systems, FindProcess always succeeds and returns a Process for the given pid, regardless of whether the process exists.

This was giving me issues on my Linux machine without this patch, so I have submitted a pull request to fix this. It complains I've not hit some checks or something. I've never submitted a PR to an open source project on any repository ever, so my apologies that I don't know what I am doing for that.

New search code for daemon_unix.go

func (d *Context) search() (daemon *os.Process, err error) {
	if len(d.PidFileName) > 0 {
		var pid int
		if pid, err = ReadPidFile(d.PidFileName); err != nil {
			return
		}
		daemon, err = os.FindProcess(pid)
		if err == nil && daemon != nil {
			// Truly check on Unix systems that the daemon is running
			// Daemon is not actually running if an error is received
			if daemon.Signal(syscall.Signal(0)) != nil {
				daemon = nil
			}
		}
	}
	return
}
@deniszh
Copy link
Collaborator

deniszh commented May 24, 2021

Thanks, I merged your fix - #72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants