system/wayland: use syscall dispatcher
All checks were successful
Test / Create distribution (push) Successful in 32s
Test / Sandbox (push) Successful in 2m6s
Test / Hpkg (push) Successful in 3m46s
Test / Sandbox (race detector) (push) Successful in 4m26s
Test / Hakurei (race detector) (push) Successful in 5m4s
Test / Hakurei (push) Successful in 2m8s
Test / Flake checks (push) Successful in 1m27s
All checks were successful
Test / Create distribution (push) Successful in 32s
Test / Sandbox (push) Successful in 2m6s
Test / Hpkg (push) Successful in 3m46s
Test / Sandbox (race detector) (push) Successful in 4m26s
Test / Hakurei (race detector) (push) Successful in 5m4s
Test / Hakurei (push) Successful in 2m8s
Test / Flake checks (push) Successful in 1m27s
This enables wayland op methods to be instrumented. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -9,11 +9,17 @@ import (
|
||||
"hakurei.app/system/wayland"
|
||||
)
|
||||
|
||||
type waylandConn interface {
|
||||
Attach(p string) (err error)
|
||||
Bind(pathname, appID, instanceID string) (*os.File, error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
// Wayland maintains a wayland socket with security-context-v1 attached via [wayland].
|
||||
// The socket stops accepting connections once the pipe referred to by sync is closed.
|
||||
// The socket is pathname only and is destroyed on revert.
|
||||
func (sys *I) Wayland(syncFd **os.File, dst, src, appID, instanceID string) *I {
|
||||
sys.ops = append(sys.ops, &waylandOp{syncFd, dst, src, appID, instanceID, wayland.Conn{}})
|
||||
sys.ops = append(sys.ops, &waylandOp{syncFd, dst, src, appID, instanceID, new(wayland.Conn)})
|
||||
return sys
|
||||
}
|
||||
|
||||
@@ -23,7 +29,7 @@ type waylandOp struct {
|
||||
dst, src string
|
||||
appID, instanceID string
|
||||
|
||||
conn wayland.Conn
|
||||
conn waylandConn
|
||||
}
|
||||
|
||||
func (w *waylandOp) Type() Enablement { return Process }
|
||||
@@ -34,43 +40,32 @@ func (w *waylandOp) apply(sys *I) error {
|
||||
return errors.New("invalid sync")
|
||||
}
|
||||
|
||||
// the Wayland op is not repeatable
|
||||
if *w.sync != nil {
|
||||
// this is a misuse of the API; do not return a wrapped error
|
||||
return errors.New("attempted to attach multiple wayland sockets")
|
||||
}
|
||||
|
||||
if err := w.conn.Attach(w.src); err != nil {
|
||||
return newOpError("wayland", err, false)
|
||||
} else {
|
||||
msg.Verbosef("wayland attached on %q", w.src)
|
||||
sys.verbosef("wayland attached on %q", w.src)
|
||||
}
|
||||
|
||||
if sp, err := w.conn.Bind(w.dst, w.appID, w.instanceID); err != nil {
|
||||
return newOpError("wayland", err, false)
|
||||
} else {
|
||||
*w.sync = sp
|
||||
msg.Verbosef("wayland listening on %q", w.dst)
|
||||
if err = os.Chmod(w.dst, 0); err != nil {
|
||||
sys.verbosef("wayland listening on %q", w.dst)
|
||||
if err = sys.chmod(w.dst, 0); err != nil {
|
||||
return newOpError("wayland", err, false)
|
||||
}
|
||||
return newOpError("wayland", acl.Update(w.dst, sys.uid, acl.Read, acl.Write, acl.Execute), false)
|
||||
return newOpError("wayland", sys.aclUpdate(w.dst, sys.uid, acl.Read, acl.Write, acl.Execute), false)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *waylandOp) revert(_ *I, ec *Criteria) error {
|
||||
if ec.hasType(w.Type()) {
|
||||
msg.Verbosef("removing wayland socket on %q", w.dst)
|
||||
if err := os.Remove(w.dst); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return newOpError("wayland", err, true)
|
||||
}
|
||||
|
||||
msg.Verbosef("detaching from wayland on %q", w.src)
|
||||
return newOpError("wayland", w.conn.Close(), true)
|
||||
} else {
|
||||
msg.Verbosef("skipping wayland cleanup on %q", w.dst)
|
||||
return nil
|
||||
func (w *waylandOp) revert(sys *I, _ *Criteria) error {
|
||||
sys.verbosef("removing wayland socket on %q", w.dst)
|
||||
if err := sys.remove(w.dst); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return newOpError("wayland", err, true)
|
||||
}
|
||||
|
||||
sys.verbosef("detaching from wayland on %q", w.src)
|
||||
return newOpError("wayland", w.conn.Close(), true)
|
||||
}
|
||||
|
||||
func (w *waylandOp) Is(o Op) bool {
|
||||
|
||||
Reference in New Issue
Block a user