mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
wgengine/monitor: prevent shutdown hang in darwin link monitor
This commit is contained in:
parent
bbb4631e04
commit
36189e2704
@ -8,8 +8,10 @@ package monitor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"errors"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
"tailscale.com/syncs"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,12 +31,14 @@ func newOSMon(logf logger.Logf) (osMon, error) {
|
|||||||
// we can just shell out to "route -n monitor". It waits for any input
|
// we can just shell out to "route -n monitor". It waits for any input
|
||||||
// but doesn't parse it. Then we poll to see if something is different.
|
// but doesn't parse it. Then we poll to see if something is different.
|
||||||
type routeMonitorSubProcMon struct {
|
type routeMonitorSubProcMon struct {
|
||||||
cmd *exec.Cmd // of "/sbin/route -n monitor"
|
closed syncs.AtomicBool
|
||||||
br *bufio.Reader
|
cmd *exec.Cmd // of "/sbin/route -n monitor"
|
||||||
buf []byte
|
br *bufio.Reader
|
||||||
|
buf []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *routeMonitorSubProcMon) Close() error {
|
func (m *routeMonitorSubProcMon) Close() error {
|
||||||
|
m.closed.Set(true)
|
||||||
if m.cmd != nil {
|
if m.cmd != nil {
|
||||||
m.cmd.Process.Kill()
|
m.cmd.Process.Kill()
|
||||||
m.cmd = nil
|
m.cmd = nil
|
||||||
@ -43,6 +47,9 @@ func (m *routeMonitorSubProcMon) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *routeMonitorSubProcMon) Receive() (message, error) {
|
func (m *routeMonitorSubProcMon) Receive() (message, error) {
|
||||||
|
if m.closed.Get() {
|
||||||
|
return nil, errors.New("monitor closed")
|
||||||
|
}
|
||||||
if m.cmd == nil {
|
if m.cmd == nil {
|
||||||
cmd := exec.Command("/sbin/route", "-n", "monitor")
|
cmd := exec.Command("/sbin/route", "-n", "monitor")
|
||||||
outPipe, err := cmd.StdoutPipe()
|
outPipe, err := cmd.StdoutPipe()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user