set HOME=/perm/$basename when starting services

Previously, HOME was inherited from the environment of the init process, which
has HOME=/ set. Of course, / is not writable on gokrazy, so this change makes
things less strict and should therefore not break any deployments.
This commit is contained in:
Michael Stapelberg 2020-05-27 18:50:52 +02:00
parent 9e57e3cf2e
commit 32f88999da

View File

@ -273,6 +273,7 @@ func supervise(s *service) {
cmd := &exec.Cmd{
Path: s.cmd.Path,
Args: s.cmd.Args,
Env: os.Environ(),
Stdout: s.Stdout,
Stderr: s.Stderr,
SysProcAttr: &syscall.SysProcAttr{
@ -282,6 +283,12 @@ func supervise(s *service) {
if attempt == 0 {
cmd.Env = append(cmd.Env, "GOKRAZY_FIRST_START=1")
}
// Designate a subdirectory under /perm as $HOME.
// This mirrors what gokrazy system daemons and
// ported daemons would do, so setting $HOME
// increases the chance that third-party daemons
// just work.
cmd.Env = append(cmd.Env, "HOME=/perm/"+filepath.Base(s.cmd.Path))
attempt++