mirror of
				https://github.com/containers/podman.git
				synced 2025-11-04 00:50:15 +08:00 
			
		
		
		
	Paul found logic errors in my earlier code for finding processes and sending signals. Some of the logic errors are associated with how methods behave on different operating systems. Created a darwin and linux approach and a windows approach. Signed-off-by: Brent Baude <bbaude@redhat.com> [NO NEW TESTS NEEDED]
		
			
				
	
	
		
			25 lines
		
	
	
		
			582 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			582 B
		
	
	
	
		
			Go
		
	
	
	
	
	
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
 | 
						|
// +build darwin dragonfly freebsd linux netbsd openbsd
 | 
						|
 | 
						|
package machine
 | 
						|
 | 
						|
import (
 | 
						|
	"os"
 | 
						|
	"syscall"
 | 
						|
)
 | 
						|
 | 
						|
func findProcess(pid int) (*os.Process, error) {
 | 
						|
	p, err := os.FindProcess(pid)
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	// On unix, findprocess will always return a process even
 | 
						|
	// if the process is not found.  you must send a 0 signal
 | 
						|
	// to the process to see if it is alive.
 | 
						|
	// https://pkg.go.dev/os#FindProcess
 | 
						|
	if err := p.Signal(syscall.Signal(0)); err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	return p, nil
 | 
						|
}
 |