forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlegetty.go
More file actions
53 lines (46 loc) · 1.19 KB
/
handlegetty.go
File metadata and controls
53 lines (46 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2022 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package domainmgr
import (
"os"
"os/exec"
"strings"
"github.com/lf-edge/eve/pkg/pillar/base"
)
// cmdlineGettyFlag should be aligned with grub.cfg in grub and 001-getty in dom0-ztools
const cmdlineGettyFlag = "getty"
var gettyStarted bool
func hasInitGettyStarted(log *base.LogObject) bool {
data, err := os.ReadFile("/proc/cmdline")
if err != nil {
log.Errorf("cannot read /proc/cmdline: %v", err)
return false
}
bootArgs := strings.Fields(string(data))
for _, arg := range bootArgs {
if arg == cmdlineGettyFlag {
return true
}
}
return false
}
func startGetty(log *base.LogObject) {
if gettyStarted {
log.Noticeln("getty already started")
return
}
if hasInitGettyStarted(log) {
log.Noticeln("getty started in init")
return
}
// INITGETTY option will run the script in background
args := []string{"/hostfs", "/bin/sh", "-c", "INITGETTY=true INSECURE=true /usr/bin/rungetty.sh"}
cmd := exec.Command("chroot", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatalf("failed to start getty: %v", err)
}
log.Noticeln("getty started")
gettyStarted = true
}