container: use absolute for pathname
All checks were successful
Test / Flake checks (push) Successful in 1m26s
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 1m59s
Test / Hakurei (push) Successful in 2m58s
Test / Hpkg (push) Successful in 3m45s
Test / Sandbox (race detector) (push) Successful in 4m11s
Test / Hakurei (race detector) (push) Successful in 4m47s
All checks were successful
Test / Flake checks (push) Successful in 1m26s
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 1m59s
Test / Hakurei (push) Successful in 2m58s
Test / Hpkg (push) Successful in 3m45s
Test / Sandbox (race detector) (push) Successful in 4m11s
Test / Hakurei (race detector) (push) Successful in 4m47s
This is simultaneously more efficient and less error-prone. This change caused minor API changes in multiple other packages. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -115,9 +115,15 @@ func buildCommand(out io.Writer) command.Command {
|
||||
|
||||
config.Identity = aid
|
||||
config.Groups = groups
|
||||
config.Data = homeDir
|
||||
config.Username = userName
|
||||
|
||||
if a, err := container.NewAbs(homeDir); err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return err
|
||||
} else {
|
||||
config.Data = a
|
||||
}
|
||||
|
||||
if wayland {
|
||||
config.Enablements |= system.EWayland
|
||||
}
|
||||
@@ -213,7 +219,7 @@ func buildCommand(out io.Writer) command.Command {
|
||||
|
||||
var psFlagShort bool
|
||||
c.NewCommand("ps", "List active instances", func(args []string) error {
|
||||
printPs(os.Stdout, time.Now().UTC(), state.NewMulti(std.Paths().RunDirPath), psFlagShort, flagJSON)
|
||||
printPs(os.Stdout, time.Now().UTC(), state.NewMulti(std.Paths().RunDirPath.String()), psFlagShort, flagJSON)
|
||||
return errSuccess
|
||||
}).Flag(&psFlagShort, "short", command.BoolFlag(false), "Print instance id")
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ func tryShort(name string) (config *hst.Config, entry *state.State) {
|
||||
if likePrefix && len(name) >= 8 {
|
||||
hlog.Verbose("argument looks like prefix")
|
||||
|
||||
s := state.NewMulti(std.Paths().RunDirPath)
|
||||
s := state.NewMulti(std.Paths().RunDirPath.String())
|
||||
if entries, err := state.Join(s); err != nil {
|
||||
log.Printf("cannot join store: %v", err)
|
||||
// drop to fetch from file
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"hakurei.app/container"
|
||||
"hakurei.app/hst"
|
||||
"hakurei.app/internal/app/state"
|
||||
"hakurei.app/internal/hlog"
|
||||
@@ -77,13 +78,13 @@ func printShowInstance(
|
||||
if len(config.Groups) > 0 {
|
||||
t.Printf(" Groups:\t%s\n", strings.Join(config.Groups, ", "))
|
||||
}
|
||||
if config.Data != "" {
|
||||
if config.Data != nil {
|
||||
t.Printf(" Data:\t%s\n", config.Data)
|
||||
}
|
||||
if config.Container != nil {
|
||||
container := config.Container
|
||||
if container.Hostname != "" {
|
||||
t.Printf(" Hostname:\t%s\n", container.Hostname)
|
||||
params := config.Container
|
||||
if params.Hostname != "" {
|
||||
t.Printf(" Hostname:\t%s\n", params.Hostname)
|
||||
}
|
||||
flags := make([]string, 0, 7)
|
||||
writeFlag := func(name string, value bool) {
|
||||
@@ -91,30 +92,32 @@ func printShowInstance(
|
||||
flags = append(flags, name)
|
||||
}
|
||||
}
|
||||
writeFlag("userns", container.Userns)
|
||||
writeFlag("devel", container.Devel)
|
||||
writeFlag("net", container.Net)
|
||||
writeFlag("device", container.Device)
|
||||
writeFlag("tty", container.Tty)
|
||||
writeFlag("mapuid", container.MapRealUID)
|
||||
writeFlag("userns", params.Userns)
|
||||
writeFlag("devel", params.Devel)
|
||||
writeFlag("net", params.Net)
|
||||
writeFlag("device", params.Device)
|
||||
writeFlag("tty", params.Tty)
|
||||
writeFlag("mapuid", params.MapRealUID)
|
||||
writeFlag("directwl", config.DirectWayland)
|
||||
writeFlag("autoetc", container.AutoEtc)
|
||||
writeFlag("autoetc", params.AutoEtc)
|
||||
if len(flags) == 0 {
|
||||
flags = append(flags, "none")
|
||||
}
|
||||
t.Printf(" Flags:\t%s\n", strings.Join(flags, " "))
|
||||
|
||||
if container.AutoRoot != "" {
|
||||
t.Printf(" Root:\t%s (%d)\n", container.AutoRoot, container.RootFlags)
|
||||
if params.AutoRoot != nil {
|
||||
t.Printf(" Root:\t%s (%d)\n", params.AutoRoot, params.RootFlags)
|
||||
}
|
||||
|
||||
etc := container.Etc
|
||||
if etc == "" {
|
||||
etc = "/etc"
|
||||
etc := params.Etc
|
||||
if etc == nil {
|
||||
etc = container.AbsFHSEtc
|
||||
}
|
||||
t.Printf(" Etc:\t%s\n", etc)
|
||||
|
||||
t.Printf(" Path:\t%s\n", config.Path)
|
||||
if config.Path != nil {
|
||||
t.Printf(" Path:\t%s\n", config.Path)
|
||||
}
|
||||
}
|
||||
if len(config.Args) > 0 {
|
||||
t.Printf(" Arguments:\t%s\n", strings.Join(config.Args, " "))
|
||||
@@ -125,12 +128,19 @@ func printShowInstance(
|
||||
if config.Container != nil && len(config.Container.Filesystem) > 0 {
|
||||
t.Printf("Filesystem\n")
|
||||
for _, f := range config.Container.Filesystem {
|
||||
if f == nil {
|
||||
g := 4
|
||||
if f.Src == nil {
|
||||
t.Println(" <invalid>")
|
||||
continue
|
||||
} else {
|
||||
g += len(f.Src.String())
|
||||
}
|
||||
if f.Dst != nil {
|
||||
g += len(f.Dst.String())
|
||||
}
|
||||
|
||||
expr := new(strings.Builder)
|
||||
expr.Grow(3 + len(f.Src) + 1 + len(f.Dst))
|
||||
expr.Grow(g)
|
||||
|
||||
if f.Device {
|
||||
expr.WriteString(" d")
|
||||
@@ -144,9 +154,14 @@ func printShowInstance(
|
||||
} else {
|
||||
expr.WriteString("+")
|
||||
}
|
||||
expr.WriteString(f.Src)
|
||||
if f.Dst != "" {
|
||||
expr.WriteString(":" + f.Dst)
|
||||
src := f.Src.String()
|
||||
if src != container.Nonexistent {
|
||||
expr.WriteString(src)
|
||||
} else {
|
||||
expr.WriteString("tmpfs")
|
||||
}
|
||||
if f.Dst != nil {
|
||||
expr.WriteString(":" + f.Dst.String())
|
||||
}
|
||||
t.Printf("%s\n", expr.String())
|
||||
}
|
||||
|
||||
@@ -83,18 +83,17 @@ App
|
||||
Identity: 0
|
||||
Enablements: (no enablements)
|
||||
Flags: none
|
||||
Etc: /etc
|
||||
Path:
|
||||
Etc: /etc/
|
||||
|
||||
`},
|
||||
{"config nil entries", nil, &hst.Config{Container: &hst.ContainerConfig{Filesystem: make([]*hst.FilesystemConfig, 1)}, ExtraPerms: make([]*hst.ExtraPermConfig, 1)}, false, false, `App
|
||||
{"config nil entries", nil, &hst.Config{Container: &hst.ContainerConfig{Filesystem: make([]hst.FilesystemConfig, 1)}, ExtraPerms: make([]*hst.ExtraPermConfig, 1)}, false, false, `App
|
||||
Identity: 0
|
||||
Enablements: (no enablements)
|
||||
Flags: none
|
||||
Etc: /etc
|
||||
Path:
|
||||
Etc: /etc/
|
||||
|
||||
Filesystem
|
||||
<invalid>
|
||||
|
||||
Extra ACL
|
||||
|
||||
@@ -277,7 +276,7 @@ App
|
||||
"filesystem": [
|
||||
{
|
||||
"dst": "/tmp/",
|
||||
"src": "tmpfs",
|
||||
"src": "/proc/nonexistent",
|
||||
"write": true
|
||||
},
|
||||
{
|
||||
@@ -304,10 +303,10 @@ App
|
||||
}
|
||||
],
|
||||
"symlink": [
|
||||
[
|
||||
"/run/user/65534",
|
||||
"/run/user/150"
|
||||
]
|
||||
{
|
||||
"target": "/run/user/65534",
|
||||
"linkname": "/run/user/150"
|
||||
}
|
||||
],
|
||||
"auto_root": "/var/lib/hakurei/base/org.debian",
|
||||
"root_flags": 2,
|
||||
@@ -409,7 +408,7 @@ App
|
||||
"filesystem": [
|
||||
{
|
||||
"dst": "/tmp/",
|
||||
"src": "tmpfs",
|
||||
"src": "/proc/nonexistent",
|
||||
"write": true
|
||||
},
|
||||
{
|
||||
@@ -436,10 +435,10 @@ App
|
||||
}
|
||||
],
|
||||
"symlink": [
|
||||
[
|
||||
"/run/user/65534",
|
||||
"/run/user/150"
|
||||
]
|
||||
{
|
||||
"target": "/run/user/65534",
|
||||
"linkname": "/run/user/150"
|
||||
}
|
||||
],
|
||||
"auto_root": "/var/lib/hakurei/base/org.debian",
|
||||
"root_flags": 2,
|
||||
@@ -595,7 +594,7 @@ func Test_printPs(t *testing.T) {
|
||||
"filesystem": [
|
||||
{
|
||||
"dst": "/tmp/",
|
||||
"src": "tmpfs",
|
||||
"src": "/proc/nonexistent",
|
||||
"write": true
|
||||
},
|
||||
{
|
||||
@@ -622,10 +621,10 @@ func Test_printPs(t *testing.T) {
|
||||
}
|
||||
],
|
||||
"symlink": [
|
||||
[
|
||||
"/run/user/65534",
|
||||
"/run/user/150"
|
||||
]
|
||||
{
|
||||
"target": "/run/user/65534",
|
||||
"linkname": "/run/user/150"
|
||||
}
|
||||
],
|
||||
"auto_root": "/var/lib/hakurei/base/org.debian",
|
||||
"root_flags": 2,
|
||||
|
||||
Reference in New Issue
Block a user