Skip to content

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

@stew3254

Description

@stew3254

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions