internal/system: relocate from system
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m17s
Test / Sandbox (race detector) (push) Successful in 4m7s
Test / Hpkg (push) Successful in 4m13s
Test / Hakurei (race detector) (push) Successful in 5m3s
Test / Flake checks (push) Successful in 1m40s
All checks were successful
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m17s
Test / Sandbox (race detector) (push) Successful in 4m7s
Test / Hpkg (push) Successful in 4m13s
Test / Hakurei (race detector) (push) Successful in 5m3s
Test / Flake checks (push) Successful in 1m40s
These packages are highly specific to hakurei and are difficult to use safely from other pieces of code. Their exported symbols are made available until v0.4.0 where they will be removed for #24. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
15a66a2b31
commit
4e7aab07d5
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"hakurei.app/container/check"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/internal/system/acl"
|
||||
)
|
||||
|
||||
// UpdatePerm calls UpdatePermType with the [Process] criteria.
|
||||
@ -13,7 +13,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/internal/system/acl"
|
||||
)
|
||||
|
||||
const testFileName = "acl.test"
|
||||
@ -3,7 +3,7 @@ package acl_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/internal/system/acl"
|
||||
)
|
||||
|
||||
func TestPerms(t *testing.T) {
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"hakurei.app/container/stub"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/internal/system/acl"
|
||||
)
|
||||
|
||||
func TestACLUpdateOp(t *testing.T) {
|
||||
@ -13,7 +13,7 @@ import (
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/dbus"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
)
|
||||
|
||||
// ErrDBusConfig is returned when a required [hst.BusConfig] argument is nil.
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"hakurei.app/system/dbus"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/dbus"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
)
|
||||
|
||||
func TestConfigArgs(t *testing.T) {
|
||||
@ -12,8 +12,8 @@ import (
|
||||
"time"
|
||||
|
||||
"hakurei.app/internal/helper"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
"hakurei.app/message"
|
||||
"hakurei.app/system/dbus"
|
||||
)
|
||||
|
||||
func TestFinalise(t *testing.T) {
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"hakurei.app/container/stub"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/internal/helper"
|
||||
"hakurei.app/system/dbus"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
)
|
||||
|
||||
func TestDBusProxyOp(t *testing.T) {
|
||||
@ -7,9 +7,9 @@ import (
|
||||
"os"
|
||||
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/system/dbus"
|
||||
"hakurei.app/system/internal/xcb"
|
||||
"hakurei.app/internal/system/acl"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
"hakurei.app/internal/system/xcb"
|
||||
)
|
||||
|
||||
type osFile interface {
|
||||
@ -10,9 +10,9 @@ import (
|
||||
|
||||
"hakurei.app/container/stub"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/system/dbus"
|
||||
"hakurei.app/system/internal/xcb"
|
||||
"hakurei.app/internal/system/acl"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
"hakurei.app/internal/system/xcb"
|
||||
)
|
||||
|
||||
// call initialises a [stub.Call].
|
||||
@ -44,7 +44,7 @@ type Op interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// TypeString extends [Enablement.String] to support [User] and [Process].
|
||||
// TypeString extends [hst.Enablement.String] to support [User] and [Process].
|
||||
func TypeString(e hst.Enablement) string {
|
||||
switch e {
|
||||
case User:
|
||||
@ -11,8 +11,8 @@ import (
|
||||
"hakurei.app/container/check"
|
||||
"hakurei.app/container/stub"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/internal/system/xcb"
|
||||
"hakurei.app/message"
|
||||
"hakurei.app/system/internal/xcb"
|
||||
)
|
||||
|
||||
func TestCriteria(t *testing.T) {
|
||||
@ -7,8 +7,8 @@ import (
|
||||
|
||||
"hakurei.app/container/check"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/system/wayland"
|
||||
"hakurei.app/internal/system/acl"
|
||||
"hakurei.app/internal/system/wayland"
|
||||
)
|
||||
|
||||
type waylandConn interface {
|
||||
@ -1,4 +1,3 @@
|
||||
// Package wayland implements Wayland security_context_v1 protocol.
|
||||
package wayland
|
||||
|
||||
import (
|
||||
@ -1,3 +1,4 @@
|
||||
// Package wayland implements Wayland security_context_v1 protocol.
|
||||
package wayland
|
||||
|
||||
//go:generate sh -c "wayland-scanner client-header `pkg-config --variable=datarootdir wayland-protocols`/wayland-protocols/staging/security-context/security-context-v1.xml security-context-v1-protocol.h"
|
||||
@ -13,10 +14,21 @@ import "C"
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrContainsNull = errors.New("string contains null character")
|
||||
const (
|
||||
// Display contains the name of the server socket
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1147)
|
||||
// which is concatenated with XDG_RUNTIME_DIR
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1171)
|
||||
// or used as-is if absolute
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1176).
|
||||
Display = "WAYLAND_DISPLAY"
|
||||
|
||||
// FallbackName is used as the wayland socket name if WAYLAND_DISPLAY is unset
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1149).
|
||||
FallbackName = "wayland-0"
|
||||
)
|
||||
|
||||
var resErr = [...]error{
|
||||
@ -27,10 +39,10 @@ var resErr = [...]error{
|
||||
|
||||
func bindWaylandFd(socketPath string, fd uintptr, appID, instanceID string, syncFd uintptr) error {
|
||||
if hasNull(appID) || hasNull(instanceID) {
|
||||
return ErrContainsNull
|
||||
return syscall.EINVAL
|
||||
}
|
||||
res := C.hakurei_bind_wayland_fd(C.CString(socketPath), C.int(fd), C.CString(appID), C.CString(instanceID), C.int(syncFd))
|
||||
return resErr[int32(res)]
|
||||
}
|
||||
|
||||
func hasNull(s string) bool { return strings.IndexByte(s, '\x00') > -1 }
|
||||
func hasNull(s string) bool { return strings.IndexByte(s, 0) > -1 }
|
||||
@ -6,8 +6,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"hakurei.app/container/stub"
|
||||
"hakurei.app/system/acl"
|
||||
"hakurei.app/system/wayland"
|
||||
"hakurei.app/internal/system/acl"
|
||||
"hakurei.app/internal/system/wayland"
|
||||
)
|
||||
|
||||
type stubWaylandConn struct {
|
||||
@ -2,7 +2,7 @@ package system
|
||||
|
||||
import (
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/internal/xcb"
|
||||
"hakurei.app/internal/system/xcb"
|
||||
)
|
||||
|
||||
// ChangeHosts inserts the target user into X11 hosts and deletes it once its [Enablement] is no longer satisfied.
|
||||
@ -5,7 +5,7 @@ import (
|
||||
|
||||
"hakurei.app/container/stub"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/system/internal/xcb"
|
||||
"hakurei.app/internal/system/xcb"
|
||||
)
|
||||
|
||||
func TestXHostOp(t *testing.T) {
|
||||
25
system/acl/deprecated.go
Normal file
25
system/acl/deprecated.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Package acl exposes the internal/system/acl package.
|
||||
//
|
||||
// Deprecated: This package will be removed in 0.4.
|
||||
package acl
|
||||
|
||||
import (
|
||||
_ "unsafe" // for go:linkname
|
||||
|
||||
"hakurei.app/internal/system/acl"
|
||||
)
|
||||
|
||||
type Perm = acl.Perm
|
||||
|
||||
const (
|
||||
Read = acl.Read
|
||||
Write = acl.Write
|
||||
Execute = acl.Execute
|
||||
)
|
||||
|
||||
// Update replaces ACL_USER entry with qualifier uid.
|
||||
//
|
||||
//go:linkname Update hakurei.app/internal/system/acl.Update
|
||||
func Update(name string, uid int, perms ...Perm) error
|
||||
|
||||
type Perms = acl.Perms
|
||||
115
system/dbus/deprecated.go
Normal file
115
system/dbus/deprecated.go
Normal file
@ -0,0 +1,115 @@
|
||||
// Package dbus exposes the internal/system/dbus package.
|
||||
//
|
||||
// Deprecated: This package will be removed in 0.4.
|
||||
package dbus
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
_ "unsafe" // for go:linkname
|
||||
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/internal/system/dbus"
|
||||
"hakurei.app/message"
|
||||
)
|
||||
|
||||
type AddrEntry = dbus.AddrEntry
|
||||
|
||||
// EqualAddrEntries returns whether two slices of [AddrEntry] are equal.
|
||||
//
|
||||
//go:linkname EqualAddrEntries hakurei.app/internal/system/dbus.EqualAddrEntries
|
||||
func EqualAddrEntries(entries, target []AddrEntry) bool
|
||||
|
||||
// Parse parses D-Bus address according to
|
||||
// https://dbus.freedesktop.org/doc/dbus-specification.html#addresses
|
||||
//
|
||||
//go:linkname Parse hakurei.app/internal/system/dbus.Parse
|
||||
func Parse(addr []byte) ([]AddrEntry, error)
|
||||
|
||||
type ParseError = dbus.ParseError
|
||||
|
||||
const (
|
||||
ErrNoColon = dbus.ErrNoColon
|
||||
ErrBadPairSep = dbus.ErrBadPairSep
|
||||
ErrBadPairKey = dbus.ErrBadPairKey
|
||||
ErrBadPairVal = dbus.ErrBadPairVal
|
||||
ErrBadValLength = dbus.ErrBadValLength
|
||||
ErrBadValByte = dbus.ErrBadValByte
|
||||
ErrBadValHexLength = dbus.ErrBadValHexLength
|
||||
ErrBadValHexByte = dbus.ErrBadValHexByte
|
||||
)
|
||||
|
||||
type BadAddressError = dbus.BadAddressError
|
||||
|
||||
// ProxyPair is an upstream dbus address and a downstream socket path.
|
||||
type ProxyPair = dbus.ProxyPair
|
||||
|
||||
// Args returns the xdg-dbus-proxy arguments equivalent of [hst.BusConfig].
|
||||
//
|
||||
//go:linkname Args hakurei.app/internal/system/dbus.Args
|
||||
func Args(c *hst.BusConfig, bus ProxyPair) (args []string)
|
||||
|
||||
// NewConfig returns the address of a new [hst.BusConfig] with optional defaults.
|
||||
//
|
||||
//go:linkname NewConfig hakurei.app/internal/system/dbus.NewConfig
|
||||
func NewConfig(id string, defaults, mpris bool) *hst.BusConfig
|
||||
|
||||
const (
|
||||
/*
|
||||
SessionBusAddress is the name of the environment variable where the address of the login session message bus is given in.
|
||||
|
||||
If that variable is not set, applications may also try to read the address from the X Window System root window property _DBUS_SESSION_BUS_ADDRESS.
|
||||
The root window property must have type STRING. The environment variable should have precedence over the root window property.
|
||||
|
||||
The address of the login session message bus is given in the DBUS_SESSION_BUS_ADDRESS environment variable.
|
||||
If DBUS_SESSION_BUS_ADDRESS is not set, or if it's set to the string "autolaunch:",
|
||||
the system should use platform-specific methods of locating a running D-Bus session server,
|
||||
or starting one if a running instance cannot be found.
|
||||
Note that this mechanism is not recommended for attempting to determine if a daemon is running.
|
||||
It is inherently racy to attempt to make this determination, since the bus daemon may be started just before or just after the determination is made.
|
||||
Therefore, it is recommended that applications do not try to make this determination for their functionality purposes, and instead they should attempt to start the server.
|
||||
|
||||
This package diverges from the specification, as the caller is unlikely to be an X client, or be in a position to autolaunch a dbus server.
|
||||
So a fallback address with a socket located in the well-known default XDG_RUNTIME_DIR formatting is used.
|
||||
*/
|
||||
SessionBusAddress = dbus.SessionBusAddress
|
||||
|
||||
/*
|
||||
SystemBusAddress is the name of the environment variable where the address of the system message bus is given in.
|
||||
|
||||
If that variable is not set, applications should try to connect to the well-known address unix:path=/var/run/dbus/system_bus_socket.
|
||||
Implementations of the well-known system bus should listen on an address that will result in that connection being successful.
|
||||
*/
|
||||
SystemBusAddress = dbus.SystemBusAddress
|
||||
|
||||
// FallbackSystemBusAddress is used when [SystemBusAddress] is not set.
|
||||
FallbackSystemBusAddress = dbus.FallbackSystemBusAddress
|
||||
)
|
||||
|
||||
// Address returns the session and system bus addresses copied from environment,
|
||||
// or appropriate fallback values if they are not set.
|
||||
//
|
||||
//go:linkname Address hakurei.app/internal/system/dbus.Address
|
||||
func Address() (session, system string)
|
||||
|
||||
// ProxyName is the file name or path to the proxy program.
|
||||
// Overriding ProxyName will only affect Proxy instance created after the change.
|
||||
//
|
||||
//go:linkname ProxyName hakurei.app/internal/system/dbus.ProxyName
|
||||
var ProxyName string
|
||||
|
||||
// Proxy holds the state of a xdg-dbus-proxy process, and should never be copied.
|
||||
type Proxy = dbus.Proxy
|
||||
|
||||
// Final describes the outcome of a proxy configuration.
|
||||
type Final = dbus.Final
|
||||
|
||||
// Finalise creates a checked argument writer for [Proxy].
|
||||
//
|
||||
//go:linkname Finalise hakurei.app/internal/system/dbus.Finalise
|
||||
func Finalise(sessionBus, systemBus ProxyPair, session, system *hst.BusConfig) (final *Final, err error)
|
||||
|
||||
// New returns a new instance of [Proxy].
|
||||
//
|
||||
//go:linkname New hakurei.app/internal/system/dbus.New
|
||||
func New(ctx context.Context, msg message.Msg, final *Final, output io.Writer) *Proxy
|
||||
50
system/deprecated.go
Normal file
50
system/deprecated.go
Normal file
@ -0,0 +1,50 @@
|
||||
// Package system exposes the internal/system package.
|
||||
//
|
||||
// Deprecated: This package will be removed in 0.4.
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "unsafe" // for go:linkname
|
||||
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/internal/system"
|
||||
"hakurei.app/message"
|
||||
)
|
||||
|
||||
// ErrDBusConfig is returned when a required hst.BusConfig argument is nil.
|
||||
//
|
||||
//go:linkname ErrDBusConfig hakurei.app/internal/system.ErrDBusConfig
|
||||
var ErrDBusConfig error
|
||||
|
||||
// OpError is returned by [I.Commit] and [I.Revert].
|
||||
type OpError = system.OpError
|
||||
|
||||
const (
|
||||
// User type is reverted at final instance exit.
|
||||
User = system.User
|
||||
// Process type is unconditionally reverted on exit.
|
||||
Process = system.Process
|
||||
|
||||
CM = system.CM
|
||||
)
|
||||
|
||||
// Criteria specifies types of Op to revert.
|
||||
type Criteria = system.Criteria
|
||||
|
||||
// Op is a reversible system operation.
|
||||
type Op = system.Op
|
||||
|
||||
// TypeString extends [Enablement.String] to support [User] and [Process].
|
||||
//
|
||||
//go:linkname TypeString hakurei.app/internal/system.TypeString
|
||||
func TypeString(e hst.Enablement) string
|
||||
|
||||
// New returns the address of a new [I] targeting uid.
|
||||
//
|
||||
//go:linkname New hakurei.app/internal/system.New
|
||||
func New(ctx context.Context, msg message.Msg, uid int) (sys *I)
|
||||
|
||||
// An I provides deferred operating system interaction. [I] must not be copied.
|
||||
// Methods of [I] must not be used concurrently.
|
||||
type I = system.I
|
||||
@ -1,5 +1,17 @@
|
||||
// Package wayland exposes the internal/system/wayland package.
|
||||
//
|
||||
// Deprecated: This package will be removed in 0.4.
|
||||
package wayland
|
||||
|
||||
import (
|
||||
_ "unsafe" // for go:linkname
|
||||
|
||||
"hakurei.app/internal/system/wayland"
|
||||
)
|
||||
|
||||
// Conn represents a connection to the wayland display server.
|
||||
type Conn = wayland.Conn
|
||||
|
||||
const (
|
||||
// WaylandDisplay contains the name of the server socket
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1147)
|
||||
@ -7,9 +19,9 @@ const (
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1171)
|
||||
// or used as-is if absolute
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1176).
|
||||
WaylandDisplay = "WAYLAND_DISPLAY"
|
||||
WaylandDisplay = wayland.Display
|
||||
|
||||
// FallbackName is used as the wayland socket name if WAYLAND_DISPLAY is unset
|
||||
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1149).
|
||||
FallbackName = "wayland-0"
|
||||
FallbackName = wayland.FallbackName
|
||||
)
|
||||
Loading…
x
Reference in New Issue
Block a user