| 1 | package managedproxy |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "os" |
| 7 | "os/exec" |
| 8 | "path/filepath" |
| 9 | "runtime" |
| 10 | "strconv" |
| 11 | ) |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | func ConfirmStopped(ctx context.Context, profile string) error { |
| 17 | path := filepath.Join(Dir(profile), "managed-process.json") |
| 18 | if runtime.GOOS == "darwin" { |
| 19 | path = servicePath(profile) |
| 20 | } |
| 21 | if _, err := os.Lstat(path); os.IsNotExist(err) { |
| 22 | return nil |
| 23 | } else if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | if runtime.GOOS == "darwin" { |
| 27 | name := "gui/" + strconv.Itoa(os.Getuid()) + "/" + label(profile) |
| 28 | err := exec.CommandContext(ctx, "/bin/launchctl", "print", name).Run() |
| 29 | var exit *exec.ExitError |
| 30 | if errors.As(err, &exit) && exit.ExitCode() == 113 { |
| 31 | return nil |
| 32 | } |
| 33 | } |
| 34 | return errors.New("无法确认此配置的代理进程已经退出") |
| 35 | } |