2024-09-22 00:29:36 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"git.ophivana.moe/cat/fortify/acl"
|
|
|
|
"git.ophivana.moe/cat/fortify/internal/state"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
term = "TERM"
|
|
|
|
display = "DISPLAY"
|
|
|
|
|
|
|
|
// https://manpages.debian.org/experimental/libwayland-doc/wl_display_connect.3.en.html
|
|
|
|
waylandDisplay = "WAYLAND_DISPLAY"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrWayland = errors.New(waylandDisplay + " unset")
|
|
|
|
ErrXDisplay = errors.New(display + " unset")
|
|
|
|
)
|
|
|
|
|
|
|
|
type ErrDisplayEnv BaseError
|
|
|
|
|
|
|
|
func (seal *appSeal) shareDisplay() error {
|
|
|
|
// pass $TERM to launcher
|
|
|
|
if t, ok := os.LookupEnv(term); ok {
|
2024-10-11 04:18:15 +09:00
|
|
|
seal.sys.setEnv(term, t)
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// set up wayland
|
|
|
|
if seal.et.Has(state.EnableWayland) {
|
|
|
|
if wd, ok := os.LookupEnv(waylandDisplay); !ok {
|
|
|
|
return (*ErrDisplayEnv)(wrapError(ErrWayland, "WAYLAND_DISPLAY is not set"))
|
2024-10-11 02:01:03 +09:00
|
|
|
} else if seal.wlDone == nil {
|
2024-10-10 12:44:08 +09:00
|
|
|
// hardlink wayland socket
|
2024-09-22 00:29:36 +09:00
|
|
|
wp := path.Join(seal.RuntimePath, wd)
|
2024-10-10 12:44:08 +09:00
|
|
|
wpi := path.Join(seal.shareLocal, "wayland")
|
2024-10-11 04:18:15 +09:00
|
|
|
w := path.Join(seal.sys.runtime, "wayland-0")
|
2024-10-10 12:44:08 +09:00
|
|
|
seal.sys.link(wp, wpi)
|
2024-10-11 04:18:15 +09:00
|
|
|
seal.sys.setEnv(waylandDisplay, w)
|
2024-10-15 02:15:55 +09:00
|
|
|
seal.sys.bwrap.Bind(wpi, w)
|
2024-09-22 00:29:36 +09:00
|
|
|
|
|
|
|
// ensure Wayland socket ACL (e.g. `/run/user/%d/wayland-%d`)
|
2024-10-10 14:33:58 +09:00
|
|
|
seal.sys.updatePermTag(state.EnableWayland, wp, acl.Read, acl.Write, acl.Execute)
|
2024-10-11 02:01:03 +09:00
|
|
|
} else {
|
|
|
|
// set wayland socket path (e.g. `/run/user/%d/wayland-%d`)
|
|
|
|
seal.wl = path.Join(seal.RuntimePath, wd)
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up X11
|
|
|
|
if seal.et.Has(state.EnableX) {
|
|
|
|
// discover X11 and grant user permission via the `ChangeHosts` command
|
|
|
|
if d, ok := os.LookupEnv(display); !ok {
|
|
|
|
return (*ErrDisplayEnv)(wrapError(ErrXDisplay, "DISPLAY is not set"))
|
|
|
|
} else {
|
|
|
|
seal.sys.changeHosts(seal.sys.Username)
|
2024-10-11 04:18:15 +09:00
|
|
|
seal.sys.setEnv(display, d)
|
2024-10-15 02:15:55 +09:00
|
|
|
seal.sys.bwrap.Bind("/tmp/.X11-unix", "/tmp/.X11-unix")
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|