fmsg: implement suspend in writer
This removes the requirement to call fmsg.Exit on every exit path, and enables direct use of the "log" package. However, fmsg.BeforeExit is still encouraged when possible to catch exit on suspended output. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -36,18 +36,18 @@ func (a *ACL) Type() Enablement {
|
||||
}
|
||||
|
||||
func (a *ACL) apply(sys *I) error {
|
||||
fmsg.VPrintln("applying ACL", a)
|
||||
fmsg.Verbose("applying ACL", a)
|
||||
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) {
|
||||
fmsg.VPrintln("stripping ACL", a)
|
||||
fmsg.Verbose("stripping ACL", a)
|
||||
return fmsg.WrapErrorSuffix(acl.UpdatePerm(a.path, sys.uid),
|
||||
fmt.Sprintf("cannot strip ACL entry from %q:", a.path))
|
||||
} else {
|
||||
fmsg.VPrintln("skipping ACL", a)
|
||||
fmsg.Verbose("skipping ACL", a)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package system
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -47,12 +48,12 @@ func (sys *I) ProxyDBus(session, system *dbus.Config, sessionPath, systemPath st
|
||||
d.proxy = dbus.New(sessionBus, systemBus)
|
||||
|
||||
defer func() {
|
||||
if fmsg.Verbose() && d.proxy.Sealed() {
|
||||
fmsg.VPrintln("sealed session proxy", session.Args(sessionBus))
|
||||
if fmsg.Load() && d.proxy.Sealed() {
|
||||
fmsg.Verbose("sealed session proxy", session.Args(sessionBus))
|
||||
if system != nil {
|
||||
fmsg.VPrintln("sealed system proxy", system.Args(systemBus))
|
||||
fmsg.Verbose("sealed system proxy", system.Args(systemBus))
|
||||
}
|
||||
fmsg.VPrintln("message bus proxy final args:", d.proxy)
|
||||
fmsg.Verbose("message bus proxy final args:", d.proxy)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -78,9 +79,9 @@ func (d *DBus) Type() Enablement {
|
||||
}
|
||||
|
||||
func (d *DBus) apply(sys *I) error {
|
||||
fmsg.VPrintf("session bus proxy on %q for upstream %q", d.proxy.Session()[1], d.proxy.Session()[0])
|
||||
fmsg.Verbosef("session bus proxy on %q for upstream %q", d.proxy.Session()[1], d.proxy.Session()[0])
|
||||
if d.system {
|
||||
fmsg.VPrintf("system bus proxy on %q for upstream %q", d.proxy.System()[1], d.proxy.System()[0])
|
||||
fmsg.Verbosef("system bus proxy on %q for upstream %q", d.proxy.System()[1], d.proxy.System()[0])
|
||||
}
|
||||
|
||||
// this starts the process and blocks until ready
|
||||
@@ -89,15 +90,15 @@ func (d *DBus) apply(sys *I) error {
|
||||
return fmsg.WrapErrorSuffix(err,
|
||||
"cannot start message bus proxy:")
|
||||
}
|
||||
fmsg.VPrintln("starting message bus proxy:", d.proxy)
|
||||
fmsg.Verbose("starting message bus proxy:", d.proxy)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DBus) revert(_ *I, _ *Criteria) error {
|
||||
// criteria ignored here since dbus is always process-scoped
|
||||
fmsg.VPrintln("terminating message bus proxy")
|
||||
fmsg.Verbose("terminating message bus proxy")
|
||||
d.proxy.Close()
|
||||
defer fmsg.VPrintln("message bus proxy exit")
|
||||
defer fmsg.Verbose("message bus proxy exit")
|
||||
return fmsg.WrapErrorSuffix(d.proxy.Wait(), "message bus proxy error:")
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ func (s *scanToFmsg) write(p []byte, a int) (int, error) {
|
||||
func (s *scanToFmsg) Dump() {
|
||||
s.mu.RLock()
|
||||
for _, msg := range s.msgbuf {
|
||||
fmsg.Println(msg)
|
||||
log.Println(msg)
|
||||
}
|
||||
s.mu.RUnlock()
|
||||
}
|
||||
|
||||
@@ -28,18 +28,18 @@ type Hardlink struct {
|
||||
func (l *Hardlink) Type() Enablement { return l.et }
|
||||
|
||||
func (l *Hardlink) apply(_ *I) error {
|
||||
fmsg.VPrintln("linking ", l)
|
||||
fmsg.Verbose("linking ", l)
|
||||
return fmsg.WrapErrorSuffix(os.Link(l.src, l.dst),
|
||||
fmt.Sprintf("cannot link %q:", l.dst))
|
||||
}
|
||||
|
||||
func (l *Hardlink) revert(_ *I, ec *Criteria) error {
|
||||
if ec.hasType(l) {
|
||||
fmsg.VPrintf("removing hard link %q", l.dst)
|
||||
fmsg.Verbosef("removing hard link %q", l.dst)
|
||||
return fmsg.WrapErrorSuffix(os.Remove(l.dst),
|
||||
fmt.Sprintf("cannot remove hard link %q:", l.dst))
|
||||
} else {
|
||||
fmsg.VPrintf("skipping hard link %q", l.dst)
|
||||
fmsg.Verbosef("skipping hard link %q", l.dst)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (m *Mkdir) Type() Enablement {
|
||||
}
|
||||
|
||||
func (m *Mkdir) apply(_ *I) error {
|
||||
fmsg.VPrintln("ensuring directory", m)
|
||||
fmsg.Verbose("ensuring directory", m)
|
||||
|
||||
// create directory
|
||||
err := os.Mkdir(m.path, m.perm)
|
||||
@@ -61,11 +61,11 @@ func (m *Mkdir) revert(_ *I, ec *Criteria) error {
|
||||
}
|
||||
|
||||
if ec.hasType(m) {
|
||||
fmsg.VPrintln("destroying ephemeral directory", m)
|
||||
fmsg.Verbose("destroying ephemeral directory", m)
|
||||
return fmsg.WrapErrorSuffix(os.Remove(m.path),
|
||||
fmt.Sprintf("cannot remove ephemeral directory %q:", m.path))
|
||||
} else {
|
||||
fmsg.VPrintln("skipping ephemeral directory", m)
|
||||
fmsg.Verbose("skipping ephemeral directory", m)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package system
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
@@ -105,9 +106,9 @@ func (sys *I) Commit(ctx context.Context) error {
|
||||
// sp is set to nil when all ops are applied
|
||||
if sp != nil {
|
||||
// rollback partial commit
|
||||
fmsg.VPrintf("commit faulted after %d ops, rolling back partial commit", len(sp.ops))
|
||||
fmsg.Verbosef("commit faulted after %d ops, rolling back partial commit", len(sp.ops))
|
||||
if err := sp.Revert(&Criteria{nil}); err != nil {
|
||||
fmsg.Println("errors returned reverting partial commit:", err)
|
||||
log.Println("errors returned reverting partial commit:", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -44,7 +44,7 @@ func (t *Tmpfile) Type() Enablement {
|
||||
func (t *Tmpfile) apply(_ *I) error {
|
||||
switch t.method {
|
||||
case tmpfileCopy:
|
||||
fmsg.VPrintln("publishing tmpfile", t)
|
||||
fmsg.Verbose("publishing tmpfile", t)
|
||||
return fmsg.WrapErrorSuffix(copyFile(t.dst, t.src),
|
||||
fmt.Sprintf("cannot copy tmpfile %q:", t.dst))
|
||||
default:
|
||||
@@ -54,11 +54,11 @@ func (t *Tmpfile) apply(_ *I) error {
|
||||
|
||||
func (t *Tmpfile) revert(_ *I, ec *Criteria) error {
|
||||
if ec.hasType(t) {
|
||||
fmsg.VPrintf("removing tmpfile %q", t.dst)
|
||||
fmsg.Verbosef("removing tmpfile %q", t.dst)
|
||||
return fmsg.WrapErrorSuffix(os.Remove(t.dst),
|
||||
fmt.Sprintf("cannot remove tmpfile %q:", t.dst))
|
||||
} else {
|
||||
fmsg.VPrintf("skipping tmpfile %q", t.dst)
|
||||
fmsg.Verbosef("skipping tmpfile %q", t.dst)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func (w Wayland) apply(sys *I) error {
|
||||
return fmsg.WrapErrorSuffix(err,
|
||||
fmt.Sprintf("cannot attach to wayland on %q:", w.pair[1]))
|
||||
} else {
|
||||
fmsg.VPrintf("wayland attached on %q", w.pair[1])
|
||||
fmsg.Verbosef("wayland attached on %q", w.pair[1])
|
||||
}
|
||||
|
||||
if sp, err := w.conn.Bind(w.pair[0], w.appID, w.instanceID); err != nil {
|
||||
@@ -53,7 +53,7 @@ func (w Wayland) apply(sys *I) error {
|
||||
fmt.Sprintf("cannot bind to socket on %q:", w.pair[0]))
|
||||
} else {
|
||||
sys.sp = sp
|
||||
fmsg.VPrintf("wayland listening on %q", w.pair[0])
|
||||
fmsg.Verbosef("wayland listening on %q", w.pair[0])
|
||||
return fmsg.WrapErrorSuffix(errors.Join(os.Chmod(w.pair[0], 0), acl.UpdatePerm(w.pair[0], sys.uid, acl.Read, acl.Write, acl.Execute)),
|
||||
fmt.Sprintf("cannot chmod socket on %q:", w.pair[0]))
|
||||
}
|
||||
@@ -61,16 +61,16 @@ func (w Wayland) apply(sys *I) error {
|
||||
|
||||
func (w Wayland) revert(_ *I, ec *Criteria) error {
|
||||
if ec.hasType(w) {
|
||||
fmsg.VPrintf("removing wayland socket on %q", w.pair[0])
|
||||
fmsg.Verbosef("removing wayland socket on %q", w.pair[0])
|
||||
if err := os.Remove(w.pair[0]); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
|
||||
fmsg.VPrintf("detaching from wayland on %q", w.pair[1])
|
||||
fmsg.Verbosef("detaching from wayland on %q", w.pair[1])
|
||||
return fmsg.WrapErrorSuffix(w.conn.Close(),
|
||||
fmt.Sprintf("cannot detach from wayland on %q:", w.pair[1]))
|
||||
} else {
|
||||
fmsg.VPrintf("skipping wayland cleanup on %q", w.pair[0])
|
||||
fmsg.Verbosef("skipping wayland cleanup on %q", w.pair[0])
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,18 +24,18 @@ func (x XHost) Type() Enablement {
|
||||
}
|
||||
|
||||
func (x XHost) apply(_ *I) error {
|
||||
fmsg.VPrintf("inserting entry %s to X11", x)
|
||||
fmsg.Verbosef("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) {
|
||||
fmsg.VPrintf("deleting entry %s from X11", x)
|
||||
fmsg.Verbosef("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 {
|
||||
fmsg.VPrintf("skipping entry %s in X11", x)
|
||||
fmsg.Verbosef("skipping entry %s in X11", x)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user