Repository: go
Issue: x/build,os/signal: TestDetectNohup and TestNohup fail on replacement darwin LUCI builders
Labels: Testing,Builders,NeedsFix,compiler/runtime

At present, LUCI is using temporary loaner Macs for darwin builders. They are getting replaced with macOS VMs. On the new bots, the `os/signal` `TestDetectNohup` and `TestNohup` fail like so:

```
=== RUN   TestDetectNohup
    signal_test.go:323: ran test with -check_sighup_ignored under nohup and it failed: expected success.
        Error: exit status 127
        Output:
        nohup: can't detach from console: Inappropriate ioctl for device
--- FAIL: TestDetectNohup (0.02s)
```

```
=== RUN   TestNohup/nohup-2
=== RUN   TestNohup/nohup-1
    signal_test.go:503: ran test with -send_uncaught_sighup=1 under nohup and it failed: expected success.
        Error: exit status 127
        Output:
        nohup: can't detach from console: Inappropriate ioctl for device
--- FAIL: TestNohup/nohup-1 (0.01s)
    signal_test.go:503: ran test with -send_uncaught_sighup=2 under nohup and it failed: expected success.
        Error: exit status 127
        Output:
        nohup: can't detach from console: Inappropriate ioctl for device
--- FAIL: TestNohup/nohup-2 (0.01s)
--- FAIL: TestNohup (0.02s)
```

I [ran into this before](https://github.com/golang/go/issues/48945#issuecomment-1247146502), but did not really understand what was going on.

I believe that this is related to the way the swarming bot is running under `launchd` on the new bots. This same failure can be reproduced using a similar service:

`/Library/LaunchDaemons/test.plist`:

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>org.golang.build.test</string>
        <key>ProgramArguments</key>
        <array>
            <string>/tmp/test.sh</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <true/>
        <key>StandardOutPath</key>
        <string>/tmp/test.log</string>
        <key>StandardErrorPath</key>
        <string>/tmp/test.log</string>
    </dict>
</plist>
```

`/tmp/test.sh`:

```
#!/bin/bash
/bin/echo foo
nohup /bin/echo bar
```

```
$ sudo launchctl load /Library/LaunchDaemons/test.plist
$ sudo cat /tmp/test.log
foo
nohup: can't detach from console: Inappropriate ioctl for device
```

I believe this is related to the [Execution Context](https://developer.apple.com/library/archive/technotes/tn2083/_index.html#//apple_ref/doc/uid/DTS10003794-CH1-SUBSECTION20) of different types of `launchd` services. My working theory is that `nohup` wants to move into the "Background" bootstrap namespace, but this type of service does not have a "Background" bootstrap namespace.

I believe this should work OK using either a "pre-login launchd agent" or "per-user launchd agent" (I believe that the existing loaner Macs use the latter), but I have not had much luck reliably converting to one of those service types so far. Since this is a fairly minor problem, I am simply documenting for now to unblock the rest of this migration.