aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/setup.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-09-17 13:48:42 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-09-17 13:48:42 +0900
commit4b7d616862dc7d8c73561b85deb0ca1fabf30781 (patch)
treed069af086d1fcfeca2f9a629e0f3eb3e2f19500f /internal/app/setup.go
parent6a6f62efa672bdb439c2f9056055193a53c1df01 (diff)
exit: move final and early code to internal package
Exit cleanup state information is now stored in a dedicated struct and built up using methods of that struct. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/app/setup.go')
-rw-r--r--internal/app/setup.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/internal/app/setup.go b/internal/app/setup.go
index 8d6eb881..c13468a0 100644
--- a/internal/app/setup.go
+++ b/internal/app/setup.go
@@ -8,7 +8,7 @@ import (
"path"
"strconv"
- "git.ophivana.moe/cat/fortify/internal/state"
+ "git.ophivana.moe/cat/fortify/internal"
"git.ophivana.moe/cat/fortify/internal/util"
"git.ophivana.moe/cat/fortify/internal/verbose"
)
@@ -22,6 +22,8 @@ type App struct {
env []string // modified via AppendEnv
command []string // set on initialisation
+ exit *internal.ExitState // assigned
+
launchOptionText string // set on initialisation
launchOption uint8 // assigned
@@ -30,8 +32,8 @@ type App struct {
runDirPath string // assigned
toolPath string // assigned
- enablements state.Enablements // set via setEnablement
- *user.User // assigned
+ enablements internal.Enablements // set via setEnablement
+ *user.User // assigned
// absolutely *no* method of this type is thread-safe
// so don't treat it as if it is
@@ -45,7 +47,7 @@ func (a *App) RunDir() string {
return a.runDirPath
}
-func (a *App) setEnablement(e state.Enablement) {
+func (a *App) setEnablement(e internal.Enablement) {
if a.enablements.Has(e) {
panic("enablement " + e.String() + " set twice")
}
@@ -53,6 +55,13 @@ func (a *App) setEnablement(e state.Enablement) {
a.enablements |= e.Mask()
}
+func (a *App) SealExit(exit *internal.ExitState) {
+ if a.exit != nil {
+ panic("application exit state sealed twice")
+ }
+ a.exit = exit
+}
+
func New(userName string, args []string, launchOptionText string) *App {
a := &App{
command: args,
@@ -96,7 +105,7 @@ func New(userName string, args []string, launchOptionText string) *App {
}
verbose.Println("Running as user", a.Username, "("+a.Uid+"),", "command:", a.command)
- if util.SdBootedV {
+ if internal.SdBootedV {
verbose.Println("System booted with systemd as init system (PID 1).")
}
@@ -120,7 +129,7 @@ func New(userName string, args []string, launchOptionText string) *App {
}
case "systemd":
a.launchOption = LaunchMethodMachineCtl
- if !util.SdBootedV {
+ if !internal.SdBootedV {
fmt.Println("System has not been booted with systemd as init system (PID 1).")
os.Exit(1)
}