verbose: remove system package interaction

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
2024-09-12 21:07:05 +09:00
parent b0aff89166
commit da6d238d8a
13 changed files with 85 additions and 107 deletions

View File

@@ -12,6 +12,7 @@ import (
"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/verbose"
)
const (
@@ -24,7 +25,7 @@ var (
dbusSystem bool
)
func (a *App) ShareDBus(dse, dsg *dbus.Config, verbose bool) {
func (a *App) ShareDBus(dse, dsg *dbus.Config, log bool) {
a.setEnablement(state.EnableDBus)
dbusSystem = dsg != nil
@@ -46,18 +47,14 @@ func (a *App) ShareDBus(dse, dsg *dbus.Config, verbose bool) {
}
if addr, ok := os.LookupEnv(dbusSessionBusAddress); !ok {
if system.V.Verbose {
fmt.Println("D-Bus: DBUS_SESSION_BUS_ADDRESS not set, assuming default format")
}
verbose.Println("D-Bus: DBUS_SESSION_BUS_ADDRESS not set, assuming default format")
sessionBus[0] = fmt.Sprintf("unix:path=/run/user/%d/bus", os.Getuid())
} else {
sessionBus[0] = addr
}
if addr, ok := os.LookupEnv(dbusSystemBusAddress); !ok {
if system.V.Verbose {
fmt.Println("D-Bus: DBUS_SYSTEM_BUS_ADDRESS not set, assuming default format")
}
verbose.Println("D-Bus: DBUS_SYSTEM_BUS_ADDRESS not set, assuming default format")
systemBus[0] = "unix:path=/run/dbus/system_bus_socket"
} else {
systemBus[0] = addr
@@ -65,15 +62,11 @@ func (a *App) ShareDBus(dse, dsg *dbus.Config, verbose bool) {
p := dbus.New(binPath, sessionBus, systemBus)
dse.Log = verbose
if system.V.Verbose {
fmt.Println("D-Bus: sealing session proxy", dse.Args(sessionBus))
}
dse.Log = log
verbose.Println("D-Bus: sealing session proxy", dse.Args(sessionBus))
if dsg != nil {
dsg.Log = verbose
if system.V.Verbose {
fmt.Println("D-Bus: sealing system proxy", dsg.Args(systemBus))
}
dsg.Log = log
verbose.Println("D-Bus: sealing system proxy", dsg.Args(systemBus))
}
if err := p.Seal(dse, dsg); err != nil {
state.Fatal("D-Bus: invalid config when sealing proxy,", err)
@@ -82,26 +75,20 @@ func (a *App) ShareDBus(dse, dsg *dbus.Config, verbose bool) {
ready := make(chan bool, 1)
done := make(chan struct{})
if system.V.Verbose {
fmt.Printf("Starting session bus proxy '%s' for address '%s'\n", dbusAddress[0], sessionBus[0])
if dsg != nil {
fmt.Printf("Starting system bus proxy '%s' for address '%s'\n", dbusAddress[1], systemBus[0])
}
verbose.Printf("Starting session bus proxy '%s' for address '%s'\n", dbusAddress[0], sessionBus[0])
if dsg != nil {
verbose.Printf("Starting system bus proxy '%s' for address '%s'\n", dbusAddress[1], systemBus[0])
}
if err := p.Start(&ready); err != nil {
state.Fatal("D-Bus: error starting proxy,", err)
}
if system.V.Verbose {
fmt.Println("D-Bus proxy launch:", p)
}
verbose.Println("D-Bus proxy launch:", p)
go func() {
if err := p.Wait(); err != nil {
fmt.Println("warn: D-Bus proxy returned error,", err)
} else {
if system.V.Verbose {
fmt.Println("D-Bus proxy uneventful wait")
}
verbose.Println("D-Bus proxy uneventful wait")
}
if err := os.Remove(target); err != nil && !errors.Is(err, os.ErrNotExist) {
fmt.Println("Error removing dangling D-Bus socket:", err)
@@ -130,10 +117,8 @@ func (a *App) ShareDBus(dse, dsg *dbus.Config, verbose bool) {
state.RegisterRevertPath(systemBus[1])
}
}
if system.V.Verbose {
fmt.Printf("Session bus proxy '%s' for address '%s' configured\n", dbusAddress[0], sessionBus[0])
if dsg != nil {
fmt.Printf("System bus proxy '%s' for address '%s' configured\n", dbusAddress[1], systemBus[0])
}
verbose.Printf("Session bus proxy '%s' for address '%s' configured\n", dbusAddress[0], sessionBus[0])
if dsg != nil {
verbose.Printf("System bus proxy '%s' for address '%s' configured\n", dbusAddress[1], systemBus[0])
}
}

View File

@@ -11,6 +11,7 @@ import (
"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/verbose"
)
func (a *App) SharePulse() {
@@ -49,9 +50,7 @@ func (a *App) SharePulse() {
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)
}
verbose.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)
}
@@ -61,8 +60,6 @@ func (a *App) SharePulse() {
state.RegisterRevertPath(pulseCookieFinal)
}
if system.V.Verbose {
fmt.Printf("PulseAudio dir '%s' configured\n", pulse)
}
verbose.Printf("PulseAudio dir '%s' configured\n", pulse)
}
}

View File

@@ -10,6 +10,7 @@ import (
"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/verbose"
)
const (
@@ -48,9 +49,7 @@ func (a *App) Run() {
cmd.Stderr = os.Stderr
cmd.Dir = system.V.RunDir
if system.V.Verbose {
fmt.Println("Executing:", cmd)
}
verbose.Println("Executing:", cmd)
if err := cmd.Start(); err != nil {
state.Fatal("Error starting process:", err)
@@ -71,9 +70,7 @@ func (a *App) Run() {
}
}
if system.V.Verbose {
fmt.Println("Process exited with exit code", r)
}
verbose.Println("Process exited with exit code", r)
state.BeforeExit()
os.Exit(r)
}
@@ -86,9 +83,7 @@ func (a *App) commandBuilderSudo() (args []string) {
// -A?
if _, ok := os.LookupEnv(sudoAskPass); ok {
if system.V.Verbose {
fmt.Printf("%s set, adding askpass flag\n", sudoAskPass)
}
verbose.Printf("%s set, adding askpass flag\n", sudoAskPass)
args = append(args, "-A")
}
@@ -115,7 +110,7 @@ func (a *App) commandBuilderMachineCtl() (args []string) {
args = append(args, "shell", "--uid="+a.Username)
// --quiet
if !system.V.Verbose {
if !verbose.Get() {
args = append(args, "--quiet")
}

View File

@@ -8,8 +8,8 @@ import (
"strconv"
"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/verbose"
)
type App struct {
@@ -65,11 +65,9 @@ func New(userName string, args []string, launchOptionText string) *App {
a.uid = u
}
if system.V.Verbose {
fmt.Println("Running as user", a.Username, "("+a.Uid+"),", "command:", a.command)
if util.SdBootedV {
fmt.Println("System booted with systemd as init system (PID 1).")
}
verbose.Println("Running as user", a.Username, "("+a.Uid+"),", "command:", a.command)
if util.SdBootedV {
verbose.Println("System booted with systemd as init system (PID 1).")
}
switch a.launchOptionText {
@@ -106,9 +104,7 @@ func New(userName string, args []string, launchOptionText string) *App {
os.Exit(1)
}
if system.V.Verbose {
fmt.Println("Determined launch method to be", a.launchOptionText, "with tool at", a.toolPath)
}
verbose.Println("Determined launch method to be", a.launchOptionText, "with tool at", a.toolPath)
return a
}

View File

@@ -8,6 +8,7 @@ import (
"git.ophivana.moe/cat/fortify/internal/acl"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/system"
"git.ophivana.moe/cat/fortify/internal/verbose"
)
const (
@@ -30,8 +31,6 @@ func (a *App) ShareWayland() {
} else {
state.RegisterRevertPath(wp)
}
if system.V.Verbose {
fmt.Printf("Wayland socket '%s' configured\n", w)
}
verbose.Printf("Wayland socket '%s' configured\n", w)
}
}

View File

@@ -5,7 +5,7 @@ import (
"os"
"git.ophivana.moe/cat/fortify/internal/state"
"git.ophivana.moe/cat/fortify/internal/system"
"git.ophivana.moe/cat/fortify/internal/verbose"
"git.ophivana.moe/cat/fortify/internal/xcb"
)
@@ -21,9 +21,7 @@ func (a *App) ShareX() {
// 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)
}
verbose.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 {