aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-11-09 18:33:19 +0900
committerOphestra <cat@gensokyo.uk>2026-11-09 18:33:19 +0900
commitb2db26370cc009866665f719fabfe860018bc087 (patch)
treeca24a0f99650ba5c5118da6701f2373414f2e594
parent210ae6435e313e5ef9f1fab5e9bdba9aff85bc92 (diff)
internal/testsuite: populate passwd database
This keeps musl happy for now. Currently, only dbus daemon and pipewire wants this, and both pieces of software will eventually be replaced, anyway. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/hakurei/testsuite/main.go1
-rw-r--r--internal/testsuite/testsuite.go32
2 files changed, 33 insertions, 0 deletions
diff --git a/cmd/hakurei/testsuite/main.go b/cmd/hakurei/testsuite/main.go
index eb3eafc4..d4582249 100644
--- a/cmd/hakurei/testsuite/main.go
+++ b/cmd/hakurei/testsuite/main.go
@@ -164,6 +164,7 @@ func checkHakurei(
func main() {
go testsuite.ReceiveSignals()
cred := syscall.Credential{Uid: 1000, Gid: 100}
+ testsuite.PopulatePasswd(&cred)
// the signal handler does not wait for termination
ctx := context.Background()
diff --git a/internal/testsuite/testsuite.go b/internal/testsuite/testsuite.go
index 6278d066..8947424f 100644
--- a/internal/testsuite/testsuite.go
+++ b/internal/testsuite/testsuite.go
@@ -47,6 +47,38 @@ func ReceiveSignals() {
log.Fatalf("terminating on signal %s", <-s)
}
+// PopulatePasswd populates /etc/passwd and /etc/group if they are missing.
+func PopulatePasswd(cred *syscall.Credential) {
+ if err := os.MkdirAll(fhs.Etc, 0755); err != nil {
+ log.Fatal(err)
+ }
+
+ uid, gid := strconv.Itoa(int(cred.Uid)), strconv.Itoa(int(cred.Gid))
+ if _, err := os.Stat(fhs.Etc + "passwd"); errors.Is(err, os.ErrNotExist) {
+ if err = os.WriteFile(
+ fhs.Etc+"passwd",
+ []byte("system:x:"+uid+":"+gid+":System user:/proc/nonexistent:/bin/sh\n"),
+ 0444,
+ ); err != nil {
+ log.Fatal(err)
+ }
+ } else if err != nil {
+ log.Fatal(err)
+ }
+
+ if _, err := os.Stat(fhs.Etc + "group"); errors.Is(err, os.ErrNotExist) {
+ if err = os.WriteFile(
+ fhs.Etc+"group",
+ []byte("users:x:"+gid+":\n"),
+ 0444,
+ ); err != nil {
+ log.Fatal(err)
+ }
+ } else if err != nil {
+ log.Fatal(err)
+ }
+}
+
// MustAppendEnv adds extra environment variables to cmd.
func MustAppendEnv(cmd *exec.Cmd, env ...string) {
if len(cmd.Env) == 0 {