diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-11 01:48:18 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-11 01:48:18 +0900 |
| commit | c8a0effe908c22c350c5c492b0e5bbeefc8749f1 (patch) | |
| tree | 095ce301c53f20aac3f306146670ce69dac30b42 /system/wayland.go | |
| parent | 8df01b71d4df56c8b601ca8398b9c09315b69cb8 (diff) | |
system/wayland: use syscall dispatcher
This enables wayland op methods to be instrumented.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/wayland.go')
| -rw-r--r-- | system/wayland.go | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/system/wayland.go b/system/wayland.go index fac6ee70..2dd0d98d 100644 --- a/system/wayland.go +++ b/system/wayland.go @@ -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 { |
