aboutsummaryrefslogtreecommitdiffhomepage
path: root/hst
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-11 21:06:44 +0900
committerOphestra <cat@gensokyo.uk>2026-03-12 00:52:18 +0900
commit04e6bc3c5c99d6a99f17cfa5f69f34fe8941aee2 (patch)
tree2ad64307c13e2f967fdf17c5f02e7682189b22e1 /hst
parent5c540f90aa5ac069a370cbef0ddd81fa268b43c5 (diff)
hst: expose scheduling policy
This is primarily useful for poorly written music players for now. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'hst')
-rw-r--r--hst/config.go16
-rw-r--r--hst/config_test.go4
2 files changed, 20 insertions, 0 deletions
diff --git a/hst/config.go b/hst/config.go
index 51ac62ec..5c020636 100644
--- a/hst/config.go
+++ b/hst/config.go
@@ -6,6 +6,7 @@ import (
"strings"
"hakurei.app/container/check"
+ "hakurei.app/container/std"
)
// Config configures an application container.
@@ -103,6 +104,10 @@ type Config struct {
// Init user namespace supplementary groups inherited by all container processes.
Groups []string `json:"groups"`
+ // Scheduling policy to set for the container. The zero value retains the
+ // current scheduling policy.
+ SchedPolicy std.SchedPolicy `json:"sched_policy,omitempty"`
+
// High level configuration applied to the underlying [container].
Container *ContainerConfig `json:"container"`
}
@@ -116,6 +121,10 @@ var (
// [Config.Identity] value.
ErrIdentityBounds = errors.New("identity out of bounds")
+ // ErrSchedPolicyBounds is returned by [Config.Validate] for an out of bounds
+ // [Config.SchedPolicy] value.
+ ErrSchedPolicyBounds = errors.New("scheduling policy out of bounds")
+
// ErrEnviron is returned by [Config.Validate] if an environment variable
// name contains '=' or NUL.
ErrEnviron = errors.New("invalid environment variable name")
@@ -138,6 +147,13 @@ func (config *Config) Validate() error {
Msg: "identity " + strconv.Itoa(config.Identity) + " out of range"}
}
+ if config.SchedPolicy < 0 || config.SchedPolicy > std.SCHED_LAST {
+ return &AppError{Step: "validate configuration", Err: ErrSchedPolicyBounds,
+ Msg: "scheduling policy " +
+ strconv.Itoa(int(config.SchedPolicy)) +
+ " out of range"}
+ }
+
if err := config.SessionBus.CheckInterfaces("session"); err != nil {
return err
}
diff --git a/hst/config_test.go b/hst/config_test.go
index 776c21e9..ac50f127 100644
--- a/hst/config_test.go
+++ b/hst/config_test.go
@@ -22,6 +22,10 @@ func TestConfigValidate(t *testing.T) {
Msg: "identity -1 out of range"}},
{"identity upper", &hst.Config{Identity: 10000}, &hst.AppError{Step: "validate configuration", Err: hst.ErrIdentityBounds,
Msg: "identity 10000 out of range"}},
+ {"sched lower", &hst.Config{SchedPolicy: -1}, &hst.AppError{Step: "validate configuration", Err: hst.ErrSchedPolicyBounds,
+ Msg: "scheduling policy -1 out of range"}},
+ {"sched upper", &hst.Config{SchedPolicy: 0xcafe}, &hst.AppError{Step: "validate configuration", Err: hst.ErrSchedPolicyBounds,
+ Msg: "scheduling policy 51966 out of range"}},
{"dbus session", &hst.Config{SessionBus: &hst.BusConfig{See: []string{""}}},
&hst.BadInterfaceError{Interface: "", Segment: "session"}},
{"dbus system", &hst.Config{SystemBus: &hst.BusConfig{See: []string{""}}},