bed72f6078
* Rename agent/proxy package to reflect that it is limited to managed proxy processes Rationale: we have several other components of the agent that relate to Connect proxies for example the ProxyConfigManager component needed for Envoy work. Those things are pretty separate from the focus of this package so far which is only concerned with managing external proxy processes so it's nota good fit to put code for that in here, yet there is a naming clash if we have other packages related to proxy functionality that are not in the `agent/proxy` package. Happy to bikeshed the name. I started by calling it `managedproxy` but `managedproxy.Manager` is especially unpleasant. `proxyprocess` seems good in that it's more specific about purpose but less clearly connected with the concept of "managed proxies". The names in use are cleaner though e.g. `proxyprocess.Manager`. This rename was completed automatically using golang.org/x/tools/cmd/gomvpkg. Depends on #4541 * Fix missed windows tagged files
39 lines
1 KiB
Go
39 lines
1 KiB
Go
// +build !windows
|
|
|
|
package proxyprocess
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
// findProcess for non-Windows. Note that this very likely doesn't
|
|
// work for all non-Windows platforms Go supports and we should expand
|
|
// support as we experience it.
|
|
func findProcess(pid int) (*os.Process, error) {
|
|
// FindProcess never fails on unix-like systems.
|
|
p, err := os.FindProcess(pid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// On Unix-like systems, we can verify a process is alive by sending
|
|
// a 0 signal. This will do nothing to the process but will still
|
|
// return errors if the process is gone.
|
|
err = p.Signal(syscall.Signal(0))
|
|
if err == nil {
|
|
return p, nil
|
|
}
|
|
|
|
return nil, fmt.Errorf("process %d is dead or running as another user", pid)
|
|
}
|
|
|
|
// configureDaemon is called prior to Start to allow system-specific setup.
|
|
func configureDaemon(cmd *exec.Cmd) {
|
|
// Start it in a new sessions (and hence process group) so that killing agent
|
|
// (even with Ctrl-C) won't kill proxy.
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
|
}
|