fmsg: produce all output through fmsg
All checks were successful
test / test (push) Successful in 17s
All checks were successful
test / test (push) Successful in 17s
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>
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"git.ophivana.moe/security/fortify/acl"
|
||||
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||
"git.ophivana.moe/security/fortify/internal/verbose"
|
||||
)
|
||||
|
||||
// UpdatePerm appends an ephemeral acl update Op.
|
||||
@@ -33,18 +32,20 @@ func (a *ACL) Type() Enablement {
|
||||
}
|
||||
|
||||
func (a *ACL) apply(sys *I) error {
|
||||
verbose.Println("applying ACL", a, "uid:", sys.uid, "type:", TypeString(a.et), "path:", a.path)
|
||||
fmsg.VPrintf("applying ACL %s uid: %d type: %s path: %q",
|
||||
a, sys.uid, TypeString(a.et), a.path)
|
||||
return fmsg.WrapErrorSuffix(acl.UpdatePerm(a.path, sys.uid, a.perms...),
|
||||
fmt.Sprintf("cannot apply ACL entry to %q:", a.path))
|
||||
}
|
||||
|
||||
func (a *ACL) revert(sys *I, ec *Criteria) error {
|
||||
if ec.hasType(a) {
|
||||
verbose.Println("stripping ACL", a, "uid:", sys.uid, "type:", TypeString(a.et), "path:", a.path)
|
||||
fmsg.VPrintf("stripping ACL %s uid: %d type: %s path: %q",
|
||||
a, sys.uid, TypeString(a.et), a.path)
|
||||
return fmsg.WrapErrorSuffix(acl.UpdatePerm(a.path, sys.uid),
|
||||
fmt.Sprintf("cannot strip ACL entry from %q:", a.path))
|
||||
} else {
|
||||
verbose.Println("skipping ACL", a, "uid:", sys.uid, "tag:", TypeString(a.et), "path:", a.path)
|
||||
fmsg.VPrintln("skipping ACL", a, "uid:", sys.uid, "tag:", TypeString(a.et), "path:", a.path)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.ophivana.moe/security/fortify/dbus"
|
||||
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||
"git.ophivana.moe/security/fortify/internal/verbose"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,12 +40,12 @@ func (sys *I) ProxyDBus(session, system *dbus.Config, sessionPath, systemPath st
|
||||
d.proxy = dbus.New(sessionBus, systemBus)
|
||||
|
||||
defer func() {
|
||||
if verbose.Get() && d.proxy.Sealed() {
|
||||
verbose.Println("sealed session proxy", session.Args(sessionBus))
|
||||
if fmsg.Verbose() && d.proxy.Sealed() {
|
||||
fmsg.VPrintln("sealed session proxy", session.Args(sessionBus))
|
||||
if system != nil {
|
||||
verbose.Println("sealed system proxy", system.Args(systemBus))
|
||||
fmsg.VPrintln("sealed system proxy", system.Args(systemBus))
|
||||
}
|
||||
verbose.Println("message bus proxy final args:", d.proxy)
|
||||
fmsg.VPrintln("message bus proxy final args:", d.proxy)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -73,9 +71,9 @@ func (d *DBus) Type() Enablement {
|
||||
}
|
||||
|
||||
func (d *DBus) apply(_ *I) error {
|
||||
verbose.Printf("session bus proxy on %q for upstream %q\n", d.proxy.Session()[1], d.proxy.Session()[0])
|
||||
fmsg.VPrintf("session bus proxy on %q for upstream %q", d.proxy.Session()[1], d.proxy.Session()[0])
|
||||
if d.system {
|
||||
verbose.Printf("system bus proxy on %q for upstream %q\n", d.proxy.System()[1], d.proxy.System()[0])
|
||||
fmsg.VPrintf("system bus proxy on %q for upstream %q", d.proxy.System()[1], d.proxy.System()[0])
|
||||
}
|
||||
|
||||
// ready channel passed to dbus package
|
||||
@@ -86,27 +84,27 @@ func (d *DBus) apply(_ *I) error {
|
||||
return fmsg.WrapErrorSuffix(err,
|
||||
"cannot start message bus proxy:")
|
||||
}
|
||||
verbose.Println("starting message bus proxy:", d.proxy)
|
||||
if verbose.Get() { // save the extra bwrap arg build when verbose logging is off
|
||||
verbose.Println("message bus proxy bwrap args:", d.proxy.Bwrap())
|
||||
fmsg.VPrintln("starting message bus proxy:", d.proxy)
|
||||
if fmsg.Verbose() { // save the extra bwrap arg build when verbose logging is off
|
||||
fmsg.VPrintln("message bus proxy bwrap args:", d.proxy.Bwrap())
|
||||
}
|
||||
|
||||
// background wait for proxy instance and notify completion
|
||||
go func() {
|
||||
if err := d.proxy.Wait(); err != nil {
|
||||
fmt.Println("fortify: message bus proxy exited with error:", err)
|
||||
fmsg.Println("message bus proxy exited with error:", err)
|
||||
go func() { ready <- err }()
|
||||
} else {
|
||||
verbose.Println("message bus proxy exit")
|
||||
fmsg.VPrintln("message bus proxy exit")
|
||||
}
|
||||
|
||||
// ensure socket removal so ephemeral directory is empty at revert
|
||||
if err := os.Remove(d.proxy.Session()[1]); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
fmt.Println("fortify: cannot remove dangling session bus socket:", err)
|
||||
fmsg.Println("cannot remove dangling session bus socket:", err)
|
||||
}
|
||||
if d.system {
|
||||
if err := os.Remove(d.proxy.System()[1]); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
fmt.Println("fortify: cannot remove dangling system bus socket:", err)
|
||||
fmsg.Println("cannot remove dangling system bus socket:", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,14 +118,14 @@ func (d *DBus) apply(_ *I) error {
|
||||
return fmsg.WrapErrorSuffix(err,
|
||||
"message bus proxy fault after start:")
|
||||
}
|
||||
verbose.Println("message bus proxy ready")
|
||||
fmsg.VPrintln("message bus proxy ready")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DBus) revert(_ *I, _ *Criteria) error {
|
||||
// criteria ignored here since dbus is always process-scoped
|
||||
verbose.Println("terminating message bus proxy")
|
||||
fmsg.VPrintln("terminating message bus proxy")
|
||||
|
||||
if err := d.proxy.Close(); err != nil {
|
||||
if errors.Is(err, os.ErrClosed) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"os"
|
||||
|
||||
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||
"git.ophivana.moe/security/fortify/internal/verbose"
|
||||
)
|
||||
|
||||
// Ensure the existence and mode of a directory.
|
||||
@@ -37,7 +36,7 @@ func (m *Mkdir) Type() Enablement {
|
||||
}
|
||||
|
||||
func (m *Mkdir) apply(_ *I) error {
|
||||
verbose.Println("ensuring directory", m)
|
||||
fmsg.VPrintln("ensuring directory", m)
|
||||
|
||||
// create directory
|
||||
err := os.Mkdir(m.path, m.perm)
|
||||
@@ -58,11 +57,11 @@ func (m *Mkdir) revert(_ *I, ec *Criteria) error {
|
||||
}
|
||||
|
||||
if ec.hasType(m) {
|
||||
verbose.Println("destroying ephemeral directory", m)
|
||||
fmsg.VPrintln("destroying ephemeral directory", m)
|
||||
return fmsg.WrapErrorSuffix(os.Remove(m.path),
|
||||
fmt.Sprintf("cannot remove ephemeral directory %q:", m.path))
|
||||
} else {
|
||||
verbose.Println("skipping ephemeral directory", m)
|
||||
fmsg.VPrintln("skipping ephemeral directory", m)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package system
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -80,7 +81,7 @@ func (sys *I) Commit() error {
|
||||
if sp != nil {
|
||||
// rollback partial commit
|
||||
if err := sp.Revert(&Criteria{nil}); err != nil {
|
||||
fmt.Println("fortify: errors returned reverting partial commit:", err)
|
||||
fmsg.Println("errors returned reverting partial commit:", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"git.ophivana.moe/security/fortify/acl"
|
||||
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||
"git.ophivana.moe/security/fortify/internal/verbose"
|
||||
)
|
||||
|
||||
// CopyFile registers an Op that copies path dst from src.
|
||||
@@ -72,15 +71,15 @@ func (t *Tmpfile) Type() Enablement {
|
||||
func (t *Tmpfile) apply(_ *I) error {
|
||||
switch t.method {
|
||||
case tmpfileCopy:
|
||||
verbose.Printf("publishing tmpfile %s\n", t)
|
||||
fmsg.VPrintln("publishing tmpfile", t)
|
||||
return fmsg.WrapErrorSuffix(copyFile(t.dst, t.src),
|
||||
fmt.Sprintf("cannot copy tmpfile %q:", t.dst))
|
||||
case tmpfileLink:
|
||||
verbose.Printf("linking tmpfile %s\n", t)
|
||||
fmsg.VPrintln("linking tmpfile", t)
|
||||
return fmsg.WrapErrorSuffix(os.Link(t.src, t.dst),
|
||||
fmt.Sprintf("cannot link tmpfile %q:", t.dst))
|
||||
case tmpfileWrite:
|
||||
verbose.Printf("writing %s\n", t)
|
||||
fmsg.VPrintln("writing", t)
|
||||
return fmsg.WrapErrorSuffix(os.WriteFile(t.dst, []byte(t.src), 0600),
|
||||
fmt.Sprintf("cannot write tmpfile %q:", t.dst))
|
||||
default:
|
||||
@@ -90,11 +89,11 @@ func (t *Tmpfile) apply(_ *I) error {
|
||||
|
||||
func (t *Tmpfile) revert(_ *I, ec *Criteria) error {
|
||||
if ec.hasType(t) {
|
||||
verbose.Printf("removing tmpfile %q\n", t.dst)
|
||||
fmsg.VPrintf("removing tmpfile %q", t.dst)
|
||||
return fmsg.WrapErrorSuffix(os.Remove(t.dst),
|
||||
fmt.Sprintf("cannot remove tmpfile %q:", t.dst))
|
||||
} else {
|
||||
verbose.Printf("skipping tmpfile %q\n", t.dst)
|
||||
fmsg.VPrintf("skipping tmpfile %q", t.dst)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||
"git.ophivana.moe/security/fortify/internal/verbose"
|
||||
"git.ophivana.moe/security/fortify/xcb"
|
||||
)
|
||||
|
||||
@@ -23,18 +22,18 @@ func (x XHost) Type() Enablement {
|
||||
}
|
||||
|
||||
func (x XHost) apply(_ *I) error {
|
||||
verbose.Printf("inserting entry %s to X11\n", x)
|
||||
fmsg.VPrintf("inserting entry %s to X11", x)
|
||||
return fmsg.WrapErrorSuffix(xcb.ChangeHosts(xcb.HostModeInsert, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)),
|
||||
fmt.Sprintf("cannot insert entry %s to X11:", x))
|
||||
}
|
||||
|
||||
func (x XHost) revert(_ *I, ec *Criteria) error {
|
||||
if ec.hasType(x) {
|
||||
verbose.Printf("deleting entry %s from X11\n", x)
|
||||
fmsg.VPrintf("deleting entry %s from X11", x)
|
||||
return fmsg.WrapErrorSuffix(xcb.ChangeHosts(xcb.HostModeDelete, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)),
|
||||
fmt.Sprintf("cannot delete entry %s from X11:", x))
|
||||
} else {
|
||||
verbose.Printf("skipping entry %s in X11\n", x)
|
||||
fmsg.VPrintf("skipping entry %s in X11", x)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user