diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index c8e0c333c..717ed6703 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -258,6 +258,7 @@ func TestLaunchdInstall(t *testing.T) { "Labelcom.yetone.magpie.serve", "/opt/my magpie/magpie%1serve", "SuccessfulExit", + "ProcessTypeStandard", "HTTP_PROXYhttp://a&b<c>@proxy", "PATH" + os.Getenv("PATH") + "", } { @@ -265,6 +266,9 @@ func TestLaunchdInstall(t *testing.T) { t.Errorf("the plist has no %q:\n%s", want, p) } } + if strings.Contains(p, "Background") { + t.Errorf("the plist still says Background:\n%s", p) + } if lint := "/usr/bin/plutil"; runtime.GOOS == "darwin" { if out, err := exec.Command(lint, "-lint", file).CombinedOutput(); err != nil { t.Errorf("plutil: %s", out) @@ -316,6 +320,19 @@ func TestLaunchdInstall(t *testing.T) { } } +// The daemon's launch agent is Standard, not Background, on every platform: +// plist only builds text, so this runs without the shell fakes and without +// a Mac. +func TestLaunchdPlistProcessType(t *testing.T) { + p := plist("/opt/magpie", []string{"serve"}, nil) + if want := "ProcessTypeStandard"; !strings.Contains(p, want) { + t.Errorf("the plist has no %q:\n%s", want, p) + } + if bad := "ProcessTypeBackground"; strings.Contains(p, bad) { + t.Errorf("the plist says %q:\n%s", bad, p) + } +} + // Windows and Android have no service of this kind: the error points to // what they have. func TestUnsupported(t *testing.T) { diff --git a/internal/daemon/launchd.go b/internal/daemon/launchd.go index c327c7b40..4406e1084 100644 --- a/internal/daemon/launchd.go +++ b/internal/daemon/launchd.go @@ -32,6 +32,8 @@ func domain() string { return "gui/" + strconv.Itoa(os.Getuid()) } func service() string { return domain() + "/" + Label } // plist is the launch agent running exe with args, with env set in it. +// ProcessType is Standard, not Background: the gateway is on the request +// path of interactive agents, and Background throttles it on macOS. func plist(exe string, args, env []string) string { s := func(v string) string { return "" + html.EscapeString(v) + "" } var b strings.Builder @@ -47,7 +49,7 @@ func plist(exe string, args, env []string) string { KeepAlive SuccessfulExit ThrottleInterval5 - ProcessTypeBackground + ProcessTypeStandard StandardOutPath` + s(logFile()) + ` StandardErrorPath` + s(logFile()) + ` `)