diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-09-04 01:20:12 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-09-04 01:20:12 +0900 |
| commit | d8f76f3b2594db4687c0203c4f2be8d3e4ef7740 (patch) | |
| tree | b1d8bfb5250d71094e397f8afa87710de1f1ca2f /internal/state/exit.go | |
| parent | 7e6eb82195c650bc34829e5cca2d2296e78c0707 (diff) | |
rename to fortify and restructure
More sandbox features will be added and this will no longer track ego's features and behaviour.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/state/exit.go')
| -rw-r--r-- | internal/state/exit.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/state/exit.go b/internal/state/exit.go new file mode 100644 index 00000000..e0e2c04a --- /dev/null +++ b/internal/state/exit.go @@ -0,0 +1,68 @@ +package state + +import ( + "errors" + "fmt" + "io/fs" + "os" + + "git.ophivana.moe/cat/fortify/internal/acl" + "git.ophivana.moe/cat/fortify/internal/system" + "git.ophivana.moe/cat/fortify/internal/xcb" +) + +func Fatal(msg ...any) { + fmt.Println(msg...) + BeforeExit() + os.Exit(1) +} + +func BeforeExit() { + if u == nil { + fmt.Println("warn: beforeExit called before app init") + return + } + + if statePath == "" { + if system.V.Verbose { + fmt.Println("State path is unset") + } + } else { + if err := os.Remove(statePath); err != nil && !errors.Is(err, fs.ErrNotExist) { + fmt.Println("Error removing state file:", err) + } + } + + if d, err := readLaunchers(); err != nil { + fmt.Println("Error reading active launchers:", err) + os.Exit(1) + } else if len(d) > 0 { + // other launchers are still active + if system.V.Verbose { + fmt.Printf("Found %d active launchers, exiting without cleaning up\n", len(d)) + } + return + } + + if system.V.Verbose { + fmt.Println("No other launchers active, will clean up") + } + + if xcbActionComplete { + if system.V.Verbose { + fmt.Printf("X11: Removing XHost entry SI:localuser:%s\n", u.Username) + } + if err := xcb.ChangeHosts(xcb.HostModeDelete, xcb.FamilyServerInterpreted, "localuser\x00"+u.Username); err != nil { + fmt.Println("Error removing XHost entry:", err) + } + } + + for _, candidate := range cleanupCandidate { + if err := acl.UpdatePerm(candidate, uid); err != nil { + fmt.Printf("Error stripping ACL entry from '%s': %s\n", candidate, err) + } + if system.V.Verbose { + fmt.Printf("Stripped ACL entry for user '%s' from '%s'\n", u.Username, candidate) + } + } +} |
