aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-21 20:47:02 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-21 20:47:02 +0900
commit42e0b168e3d75389dfb968aebf9f5629d64782f9 (patch)
treee6b430205213c62bc06275c6d84e6037d40f5c3f /internal/app
parent380d1f45851b7dffb963c51da96a17ba41f3cfb8 (diff)
fmsg: produce all output through fmsg
The behaviour of print functions from package fmt is not thread safe. Functions provided by fmsg wrap around Logger methods. This makes prefix much cleaner and makes it easy to deal with future changes to logging. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/app')
-rw-r--r--internal/app/launch.machinectl.go4
-rw-r--r--internal/app/launch.sudo.go4
-rw-r--r--internal/app/seal.go5
-rw-r--r--internal/app/start.go18
4 files changed, 14 insertions, 17 deletions
diff --git a/internal/app/launch.machinectl.go b/internal/app/launch.machinectl.go
index c06e8a6c..32f06740 100644
--- a/internal/app/launch.machinectl.go
+++ b/internal/app/launch.machinectl.go
@@ -4,7 +4,7 @@ import (
"os/exec"
"strings"
- "git.ophivana.moe/security/fortify/internal/verbose"
+ "git.ophivana.moe/security/fortify/internal/fmsg"
)
func (a *app) commandBuilderMachineCtl(shimEnv string) (args []string) {
@@ -14,7 +14,7 @@ func (a *app) commandBuilderMachineCtl(shimEnv string) (args []string) {
args = append(args, "shell", "--uid="+a.seal.sys.user.Username)
// --quiet
- if !verbose.Get() {
+ if !fmsg.Verbose() {
args = append(args, "--quiet")
}
diff --git a/internal/app/launch.sudo.go b/internal/app/launch.sudo.go
index 129ef328..2df7be0f 100644
--- a/internal/app/launch.sudo.go
+++ b/internal/app/launch.sudo.go
@@ -3,7 +3,7 @@ package app
import (
"os"
- "git.ophivana.moe/security/fortify/internal/verbose"
+ "git.ophivana.moe/security/fortify/internal/fmsg"
)
const (
@@ -18,7 +18,7 @@ func (a *app) commandBuilderSudo(shimEnv string) (args []string) {
// -A?
if _, ok := os.LookupEnv(sudoAskPass); ok {
- verbose.Printf("%s set, adding askpass flag\n", sudoAskPass)
+ fmsg.VPrintln(sudoAskPass, "set, adding askpass flag")
args = append(args, "-A")
}
diff --git a/internal/app/seal.go b/internal/app/seal.go
index 7de6aecb..f0fe5582 100644
--- a/internal/app/seal.go
+++ b/internal/app/seal.go
@@ -14,7 +14,6 @@ import (
"git.ophivana.moe/security/fortify/internal/shim"
"git.ophivana.moe/security/fortify/internal/state"
"git.ophivana.moe/security/fortify/internal/system"
- "git.ophivana.moe/security/fortify/internal/verbose"
)
const (
@@ -152,7 +151,7 @@ func (a *app) Seal(config *Config) error {
// map sandbox config to bwrap
if config.Confinement.Sandbox == nil {
- verbose.Println("sandbox configuration not supplied, PROCEED WITH CAUTION")
+ fmsg.VPrintln("sandbox configuration not supplied, PROCEED WITH CAUTION")
// permissive defaults
conf := &SandboxConfig{
@@ -242,7 +241,7 @@ func (a *app) Seal(config *Config) error {
}
// verbose log seal information
- verbose.Println("created application seal as user",
+ fmsg.VPrintln("created application seal as user",
seal.sys.user.Username, "("+seal.sys.user.Uid+"),",
"method:", config.Method+",",
"launcher:", seal.toolPath+",",
diff --git a/internal/app/start.go b/internal/app/start.go
index 3106a1e8..b6c94041 100644
--- a/internal/app/start.go
+++ b/internal/app/start.go
@@ -7,7 +7,6 @@ import (
"os/exec"
"path"
"path/filepath"
- "strconv"
"strings"
"time"
@@ -16,7 +15,6 @@ import (
"git.ophivana.moe/security/fortify/internal/shim"
"git.ophivana.moe/security/fortify/internal/state"
"git.ophivana.moe/security/fortify/internal/system"
- "git.ophivana.moe/security/fortify/internal/verbose"
)
// Start starts the fortified child
@@ -71,14 +69,14 @@ func (a *app) Start() error {
Bwrap: a.seal.sys.bwrap,
WL: a.seal.wl != nil,
- Verbose: verbose.Get(),
+ Verbose: fmsg.Verbose(),
}, a.seal.wl); err != nil {
return fmsg.WrapErrorSuffix(err,
"cannot serve shim setup:")
}
// start shim
- verbose.Println("starting shim as target user:", a.cmd)
+ fmsg.VPrintln("starting shim as target user:", a.cmd)
if err := a.cmd.Start(); err != nil {
return fmsg.WrapErrorSuffix(err,
"cannot start process:")
@@ -178,12 +176,12 @@ func (a *app) Wait() (int, error) {
r = a.cmd.ProcessState.ExitCode()
}
- verbose.Println("process", strconv.Itoa(a.cmd.Process.Pid), "exited with exit code", r)
+ fmsg.VPrintf("process %d exited with exit code %d", a.cmd.Process.Pid, r)
// close wayland connection
if a.seal.wl != nil {
if err := a.seal.wl.Close(); err != nil {
- fmt.Println("fortify: cannot close wayland connection:", err)
+ fmsg.Println("cannot close wayland connection:", err)
}
}
@@ -205,10 +203,10 @@ func (a *app) Wait() (int, error) {
} else {
if l := len(states); l == 0 {
// cleanup globals as the final launcher
- verbose.Println("no other launchers active, will clean up globals")
+ fmsg.VPrintln("no other launchers active, will clean up globals")
ec.Set(system.User)
} else {
- verbose.Printf("found %d active launchers, cleaning up without globals\n", l)
+ fmsg.VPrintf("found %d active launchers, cleaning up without globals", l)
}
// accumulate capabilities of other launchers
@@ -222,7 +220,7 @@ func (a *app) Wait() (int, error) {
ec.Set(i)
}
}
- if verbose.Get() {
+ if fmsg.Verbose() {
labels := make([]string, 0, system.ELen+1)
for i := system.Enablement(0); i < system.Enablement(system.ELen+2); i++ {
if ec.Has(i) {
@@ -230,7 +228,7 @@ func (a *app) Wait() (int, error) {
}
}
if len(labels) > 0 {
- verbose.Println("reverting operations labelled", strings.Join(labels, ", "))
+ fmsg.VPrintln("reverting operations labelled", strings.Join(labels, ", "))
}
}