Code around sleep was written into the service manager's sleep units by the module that needed it, and the mesh could not tell a sleeping machine from a lost one. power runs every module's code for the six moments, each piece bounded, owns logind's power handling from its settings, and says booted, sleeping, woke, shutting-down and the power source on the bus, sleeping under logind's delay lock before the machine sleeps.
31 lines
686 B
Go
31 lines
686 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Run on a real machine with MESH_LIVE=1: logind gives this account a delay lock, and it shows.
|
|
func TestLiveLogindGivesADelayLock(t *testing.T) {
|
|
if os.Getenv("MESH_LIVE") == "" {
|
|
t.Skip("set MESH_LIVE=1 on a machine with logind")
|
|
}
|
|
l, err := DialLogin1()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer l.Close()
|
|
f, err := l.Inhibit("sleep:shutdown", "mesh power", "live test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, _ := exec.Command("systemd-inhibit", "--list", "--no-pager").CombinedOutput()
|
|
if !strings.Contains(string(out), "mesh power") {
|
|
t.Fatalf("not listed:\n%s", out)
|
|
}
|
|
t.Logf("%s", out)
|
|
f.Close()
|
|
}
|