| 1 | //go:build !linux |
| 2 | |
| 3 | package thin |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "net" |
| 8 | "os" |
| 9 | |
| 10 | "amadan.net/oficina/equipo/internal/runner" |
| 11 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 12 | ) |
| 13 | |
| 14 | var ( |
| 15 | errToolSocketPath = errors.New("tool socket path too long") |
| 16 | errToolRoot = errors.New("tool socket root is not a directory") |
| 17 | ) |
| 18 | |
| 19 | // A step's tool socket on a Mac: <scratch root>/t/<random>/s |
| 20 | // (toolsocket_layout.go), dialled by its path. |
| 21 | const ( |
| 22 | toolDirPrefix = macToolDirPrefix |
| 23 | toolSocketName = macToolSocketName |
| 24 | ) |
| 25 | |
| 26 | // toolRoot is the private directory a runner's tool sockets go under, |
| 27 | // created 0700 if it is missing: never a link, always this user's. |
| 28 | func toolRoot(c runner.Config) (string, error) { |
| 29 | root := macToolRoot(c) |
| 30 | if err := os.MkdirAll(root, 0700); err != nil { |
| 31 | return "", err |
| 32 | } |
| 33 | info, err := os.Lstat(root) |
| 34 | if err != nil { |
| 35 | return "", err |
| 36 | } |
| 37 | if !info.IsDir() { |
| 38 | return "", errToolRoot |
| 39 | } |
| 40 | if info.Mode().Perm() != 0700 { |
| 41 | if err := os.Chmod(root, 0700); err != nil { |
| 42 | return "", err |
| 43 | } |
| 44 | } |
| 45 | return root, nil |
| 46 | } |
| 47 | |
| 48 | // listenToolSocket binds the socket at path, which must fit a Mac's |
| 49 | // sun_path: it is refused, never cut short. |
| 50 | func listenToolSocket(_, path string) (*net.UnixListener, error) { |
| 51 | if len(path) > provider.MaxDarwinSocketPath { |
| 52 | return nil, errToolSocketPath |
| 53 | } |
| 54 | return net.ListenUnix("unix", &net.UnixAddr{Name: path, Net: "unix"}) |
| 55 | } |
| 56 | |