Skip to content

Commit

Permalink
chore: wip on missing optional features
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Dec 24, 2024
1 parent 4a6d76a commit 3a67d98
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
1 change: 1 addition & 0 deletions container/container_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (c *Container) Init(reexecCmd string, reexecArgs []string) error {
})
}

// FIXME: why does this segfault??
// if ns.Type == specs.TimeNamespace {
// if c.Spec.Linux.TimeOffsets != nil && len(c.Spec.Linux.TimeOffsets) > 0 {
// var tos bytes.Buffer
Expand Down
25 changes: 10 additions & 15 deletions container/container_reexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,10 @@ func (c *Container) Reexec() error {
}

if c.Spec.Linux.Sysctl != nil {

Check failure on line 119 in container/container_reexec.go

View workflow job for this annotation

GitHub Actions / build

empty branch (SA9003)
if len(c.Spec.Linux.Sysctl) > 0 {
// fmt.Println(c.Spec.Linux.Sysctl)
// for k, v := range c.Spec.Linux.Sysctl {
// fmt.Print(k, v)
// kp := strings.ReplaceAll(k, ".", "/")
// if err := os.WriteFile(
// path.Join("/proc/sys", kp),
// []byte(v),
// 0644,
// ); err != nil {
// // return fmt.Errorf("write sysctl (%s: %s): %w", kp, v, err)
// }
// }
}
// FIXME: why does this segfault??
// if err := sysctl.SetSysctl(c.Spec.Linux.Sysctl); err != nil {
// return fmt.Errorf("set sysctl: %w", err)
// }
}

if err := filesystem.MountMaskedPaths(
Expand Down Expand Up @@ -215,7 +205,12 @@ func (c *Container) Reexec() error {
}
}

// TODO: IOPriority
if c.Spec.Process.IOPriority != nil {

Check failure on line 208 in container/container_reexec.go

View workflow job for this annotation

GitHub Actions / build

empty branch (SA9003)
// FIXME: why does this segfault??
// if err := iopriority.SetIOPriority(*c.Spec.Process.IOPriority); err != nil {
// return fmt.Errorf("set iop: %w", err)
// }
}

if err := syscall.Setuid(int(c.Spec.Process.User.UID)); err != nil {
return fmt.Errorf("set UID: %w", err)
Expand Down
29 changes: 29 additions & 0 deletions iopriority/iopriority.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package iopriority

import (
"fmt"

"github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/sys/unix"
)

var IOPrioClassMapping = map[specs.IOPriorityClass]int{
specs.IOPRIO_CLASS_RT: 1,
specs.IOPRIO_CLASS_BE: 2,
specs.IOPRIO_CLASS_IDLE: 3,
}

func SetIOPriority(iop specs.LinuxIOPriority) error {
class, ok := IOPrioClassMapping[iop.Class]
if !ok {
return fmt.Errorf("unknown ioprio class: %s", iop.Class)
}

ioprio := (class << 13) | iop.Priority

if _, _, errno := unix.Syscall(unix.SYS_IOPRIO_SET, 1, 0, uintptr(ioprio)); errno != 0 {
return fmt.Errorf("set io priority: %w", errno)
}

return nil
}
24 changes: 24 additions & 0 deletions sysctl/sysctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sysctl

import (
"fmt"
"os"
"path"
"strings"
)

func SetSysctl(sc map[string]string) error {
for k, v := range sc {
fmt.Print(k, v)
kp := strings.ReplaceAll(k, ".", "/")
if err := os.WriteFile(
path.Join("/proc/sys", kp),
[]byte(v),
0644,
); err != nil {
return fmt.Errorf("write sysctl (%s: %s): %w", kp, v, err)
}
}

return nil
}

0 comments on commit 3a67d98

Please sign in to comment.