From 62cb8a91b603546314034ded1e9d6ddfbd6ef106 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sun, 22 Sep 2024 00:29:36 +0900 Subject: app: clean up interactions and handle all application state and setup/teardown There was an earlier attempt of cleaning up the app package however it ended up creating even more of a mess and the code structure largely still looked like Ego with state setup scattered everywhere and a bunch of ugly hacks had to be implemented to keep track of all of them. In this commit the entire app package is rewritten to track everything that has to do with an app in one thread safe value. In anticipation of the client/server split also made changes: - Console messages are cleaned up to be consistent - State tracking is fully rewritten to be cleaner and usable for multiple process and client/server - Encapsulate errors to easier identify type of action causing the error as well as additional info - System-level setup operations is grouped in a way that can be collectively committed/reverted and gracefully handles errors returned by each operation - Resource sharing is made more fine-grained with PID-scoped resources whenever possible, a few remnants (X11, Wayland, PulseAudio) will be addressed when a generic proxy is available - Application setup takes a JSON-friendly config struct and deterministically generates system setup operations Signed-off-by: Ophestra Umiker --- internal/state/data.go | 59 -------------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 internal/state/data.go (limited to 'internal/state/data.go') diff --git a/internal/state/data.go b/internal/state/data.go deleted file mode 100644 index 45493885..00000000 --- a/internal/state/data.go +++ /dev/null @@ -1,59 +0,0 @@ -package state - -import ( - "encoding/gob" - "os" - "path" - - "git.ophivana.moe/cat/fortify/internal" -) - -// we unfortunately have to assume there are never races between processes -// this and launcher should eventually be replaced by a server process - -type launcherState struct { - PID int - Launcher string - Argv []string - Command []string - Capability internal.Enablements -} - -// ReadLaunchers reads all launcher state file entries for the requested user -// and if decode is true decodes these launchers as well. -func ReadLaunchers(runDirPath, uid string, decode bool) ([]*launcherState, error) { - var f *os.File - var r []*launcherState - launcherPrefix := path.Join(runDirPath, uid) - - if pl, err := os.ReadDir(launcherPrefix); err != nil { - return nil, err - } else { - for _, e := range pl { - if err = func() error { - if f, err = os.Open(path.Join(launcherPrefix, e.Name())); err != nil { - return err - } else { - defer func() { - if f.Close() != nil { - // unreachable - panic("foreign state file closed prematurely") - } - }() - - var s launcherState - r = append(r, &s) - if decode { - return gob.NewDecoder(f).Decode(&s) - } else { - return nil - } - } - }(); err != nil { - return nil, err - } - } - } - - return r, nil -} -- cgit v1.3.1