diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 109 |
1 files changed, 8 insertions, 101 deletions
@@ -6,7 +6,6 @@ import ( "fmt" "io/fs" "os" - "path" "strconv" "syscall" @@ -14,8 +13,6 @@ import ( "git.ophivana.moe/cat/fortify/internal/app" "git.ophivana.moe/cat/fortify/internal/state" "git.ophivana.moe/cat/fortify/internal/system" - "git.ophivana.moe/cat/fortify/internal/util" - "git.ophivana.moe/cat/fortify/internal/xcb" ) var ( @@ -30,14 +27,6 @@ func tryVersion() { } } -const ( - term = "TERM" - display = "DISPLAY" - - // https://manpages.debian.org/experimental/libwayland-doc/wl_display_connect.3.en.html - waylandDisplay = "WAYLAND_DISPLAY" -) - func main() { flag.Parse() @@ -105,102 +94,20 @@ func main() { } } - // ensure Wayland socket ACL (e.g. `/run/user/%d/wayland-%d`) - if w, ok := os.LookupEnv(waylandDisplay); !ok { - if system.V.Verbose { - fmt.Println("Wayland: WAYLAND_DISPLAY not set, skipping") - } - } else { - // add environment variable for new process - wp := path.Join(system.V.Runtime, w) - a.AppendEnv(waylandDisplay, wp) - if err := acl.UpdatePerm(wp, a.UID(), acl.Read, acl.Write, acl.Execute); err != nil { - state.Fatal(fmt.Sprintf("Error preparing Wayland '%s':", w), err) - } else { - state.RegisterRevertPath(wp) - } - if system.V.Verbose { - fmt.Printf("Wayland socket '%s' configured\n", w) - } + if mustWayland { + a.ShareWayland() } - // discovery X11 and grant user permission via the `ChangeHosts` command - if d, ok := os.LookupEnv(display); !ok { - if system.V.Verbose { - fmt.Println("X11: DISPLAY not set, skipping") - } - } else { - // add environment variable for new process - a.AppendEnv(display, d) - - if system.V.Verbose { - fmt.Printf("X11: Adding XHost entry SI:localuser:%s to display '%s'\n", a.Username, d) - } - if err := xcb.ChangeHosts(xcb.HostModeInsert, xcb.FamilyServerInterpreted, "localuser\x00"+a.Username); err != nil { - state.Fatal(fmt.Sprintf("Error adding XHost entry to '%s':", d), err) - } else { - state.XcbActionComplete() - } + if mustX { + a.ShareX() } - // ensure PulseAudio directory ACL (e.g. `/run/user/%d/pulse`) - pulse := path.Join(system.V.Runtime, "pulse") - pulseS := path.Join(pulse, "native") - if s, err := os.Stat(pulse); err != nil { - if !errors.Is(err, fs.ErrNotExist) { - state.Fatal("Error accessing PulseAudio directory:", err) - } - if mustPulse { - state.Fatal("PulseAudio is unavailable") - } - if system.V.Verbose { - fmt.Printf("PulseAudio dir '%s' not found, skipping\n", pulse) - } - } else { - // add environment variable for new process - a.AppendEnv(util.PulseServer, "unix:"+pulseS) - if err = acl.UpdatePerm(pulse, a.UID(), acl.Execute); err != nil { - state.Fatal("Error preparing PulseAudio:", err) - } else { - state.RegisterRevertPath(pulse) - } - - // ensure PulseAudio socket permission (e.g. `/run/user/%d/pulse/native`) - if s, err = os.Stat(pulseS); err != nil { - if errors.Is(err, fs.ErrNotExist) { - state.Fatal("PulseAudio directory found but socket does not exist") - } - state.Fatal("Error accessing PulseAudio socket:", err) - } else { - if m := s.Mode(); m&0o006 != 0o006 { - state.Fatal(fmt.Sprintf("Unexpected permissions on '%s':", pulseS), m) - } - } - - // Publish current user's pulse-cookie for target user - pulseCookieSource := util.DiscoverPulseCookie() - pulseCookieFinal := path.Join(system.V.Share, "pulse-cookie") - a.AppendEnv(util.PulseCookie, pulseCookieFinal) - if system.V.Verbose { - fmt.Printf("Publishing PulseAudio cookie '%s' to '%s'\n", pulseCookieSource, pulseCookieFinal) - } - if err = util.CopyFile(pulseCookieFinal, pulseCookieSource); err != nil { - state.Fatal("Error copying PulseAudio cookie:", err) - } - if err = acl.UpdatePerm(pulseCookieFinal, a.UID(), acl.Read); err != nil { - state.Fatal("Error publishing PulseAudio cookie:", err) - } else { - state.RegisterRevertPath(pulseCookieFinal) - } - - if system.V.Verbose { - fmt.Printf("PulseAudio dir '%s' configured\n", pulse) - } + if mustDBus { + a.ShareDBus() } - // pass $TERM to launcher - if t, ok := os.LookupEnv(term); ok { - a.AppendEnv(term, t) + if mustPulse { + a.SharePulse() } a.Run() |
