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

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:
Ophestra 2025-11-13 01:15:19 +09:00
parent 15a66a2b31
commit 4e7aab07d5
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
54 changed files with 243 additions and 30 deletions

View File

@ -8,7 +8,7 @@ import (
"hakurei.app/container/check" "hakurei.app/container/check"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
) )
// UpdatePerm calls UpdatePermType with the [Process] criteria. // UpdatePerm calls UpdatePermType with the [Process] criteria.

View File

@ -13,7 +13,7 @@ import (
"strconv" "strconv"
"testing" "testing"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
) )
const testFileName = "acl.test" const testFileName = "acl.test"

View File

@ -3,7 +3,7 @@ package acl_test
import ( import (
"testing" "testing"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
) )
func TestPerms(t *testing.T) { func TestPerms(t *testing.T) {

View File

@ -7,7 +7,7 @@ import (
"hakurei.app/container/stub" "hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
) )
func TestACLUpdateOp(t *testing.T) { func TestACLUpdateOp(t *testing.T) {

View File

@ -13,7 +13,7 @@ import (
"hakurei.app/container" "hakurei.app/container"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/dbus" "hakurei.app/internal/system/dbus"
) )
// ErrDBusConfig is returned when a required [hst.BusConfig] argument is nil. // ErrDBusConfig is returned when a required [hst.BusConfig] argument is nil.

View File

@ -5,7 +5,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"hakurei.app/system/dbus" "hakurei.app/internal/system/dbus"
) )
func TestParse(t *testing.T) { func TestParse(t *testing.T) {

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/dbus" "hakurei.app/internal/system/dbus"
) )
func TestConfigArgs(t *testing.T) { func TestConfigArgs(t *testing.T) {

View File

@ -12,8 +12,8 @@ import (
"time" "time"
"hakurei.app/internal/helper" "hakurei.app/internal/helper"
"hakurei.app/internal/system/dbus"
"hakurei.app/message" "hakurei.app/message"
"hakurei.app/system/dbus"
) )
func TestFinalise(t *testing.T) { func TestFinalise(t *testing.T) {

View File

@ -12,7 +12,7 @@ import (
"hakurei.app/container/stub" "hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/helper" "hakurei.app/internal/helper"
"hakurei.app/system/dbus" "hakurei.app/internal/system/dbus"
) )
func TestDBusProxyOp(t *testing.T) { func TestDBusProxyOp(t *testing.T) {

View File

@ -7,9 +7,9 @@ import (
"os" "os"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
"hakurei.app/system/dbus" "hakurei.app/internal/system/dbus"
"hakurei.app/system/internal/xcb" "hakurei.app/internal/system/xcb"
) )
type osFile interface { type osFile interface {

View File

@ -10,9 +10,9 @@ import (
"hakurei.app/container/stub" "hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
"hakurei.app/system/dbus" "hakurei.app/internal/system/dbus"
"hakurei.app/system/internal/xcb" "hakurei.app/internal/system/xcb"
) )
// call initialises a [stub.Call]. // call initialises a [stub.Call].

View File

@ -44,7 +44,7 @@ type Op interface {
String() string 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 { func TypeString(e hst.Enablement) string {
switch e { switch e {
case User: case User:

View File

@ -11,8 +11,8 @@ import (
"hakurei.app/container/check" "hakurei.app/container/check"
"hakurei.app/container/stub" "hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/internal/system/xcb"
"hakurei.app/message" "hakurei.app/message"
"hakurei.app/system/internal/xcb"
) )
func TestCriteria(t *testing.T) { func TestCriteria(t *testing.T) {

View File

@ -7,8 +7,8 @@ import (
"hakurei.app/container/check" "hakurei.app/container/check"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
"hakurei.app/system/wayland" "hakurei.app/internal/system/wayland"
) )
type waylandConn interface { type waylandConn interface {

View File

@ -1,4 +1,3 @@
// Package wayland implements Wayland security_context_v1 protocol.
package wayland package wayland
import ( import (

View File

@ -1,3 +1,4 @@
// Package wayland implements Wayland security_context_v1 protocol.
package wayland 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" //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 ( import (
"errors" "errors"
"strings" "strings"
"syscall"
) )
var ( const (
ErrContainsNull = errors.New("string contains null character") // 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{ var resErr = [...]error{
@ -27,10 +39,10 @@ var resErr = [...]error{
func bindWaylandFd(socketPath string, fd uintptr, appID, instanceID string, syncFd uintptr) error { func bindWaylandFd(socketPath string, fd uintptr, appID, instanceID string, syncFd uintptr) error {
if hasNull(appID) || hasNull(instanceID) { 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)) 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)] 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 }

View File

@ -6,8 +6,8 @@ import (
"testing" "testing"
"hakurei.app/container/stub" "hakurei.app/container/stub"
"hakurei.app/system/acl" "hakurei.app/internal/system/acl"
"hakurei.app/system/wayland" "hakurei.app/internal/system/wayland"
) )
type stubWaylandConn struct { type stubWaylandConn struct {

View File

@ -2,7 +2,7 @@ package system
import ( import (
"hakurei.app/hst" "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. // ChangeHosts inserts the target user into X11 hosts and deletes it once its [Enablement] is no longer satisfied.

View File

@ -5,7 +5,7 @@ import (
"hakurei.app/container/stub" "hakurei.app/container/stub"
"hakurei.app/hst" "hakurei.app/hst"
"hakurei.app/system/internal/xcb" "hakurei.app/internal/system/xcb"
) )
func TestXHostOp(t *testing.T) { func TestXHostOp(t *testing.T) {

25
system/acl/deprecated.go Normal file
View 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
View 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
View 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

View File

@ -1,5 +1,17 @@
// Package wayland exposes the internal/system/wayland package.
//
// Deprecated: This package will be removed in 0.4.
package wayland 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 ( const (
// WaylandDisplay contains the name of the server socket // WaylandDisplay contains the name of the server socket
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1147) // (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) // (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1171)
// or used as-is if absolute // or used as-is if absolute
// (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1176). // (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 // 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). // (https://gitlab.freedesktop.org/wayland/wayland/-/blob/1.23.1/src/wayland-client.c#L1149).
FallbackName = "wayland-0" FallbackName = wayland.FallbackName
) )