1
0
mirror of https://github.com/rancher/os.git synced 2025-07-31 22:47:16 +00:00

Check the tty before adding to respawn.conf

This commit is contained in:
niusmallnan 2018-10-17 17:57:03 +08:00 committed by niusmallnan
parent 1a2c711d1e
commit 7c13d76066

View File

@ -11,9 +11,10 @@ import (
"strings"
"syscall"
"github.com/codegangsta/cli"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/sys/unix"
"github.com/codegangsta/cli"
"github.com/rancher/os/cmd/cloudinitexecute"
"github.com/rancher/os/config"
"github.com/rancher/os/config/cmdline"
@ -239,6 +240,9 @@ func generateRespawnConf(cmdline, user string, sshd, recovery bool) string {
for i := 1; i < 7; i++ {
tty := fmt.Sprintf("tty%d", i)
if !istty(tty) {
continue
}
respawnConf.WriteString(gettyCmd)
if allowAutoLogin && strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
@ -252,6 +256,10 @@ func generateRespawnConf(cmdline, user string, sshd, recovery bool) string {
continue
}
if !istty(tty) {
continue
}
respawnConf.WriteString(gettyCmd)
if allowAutoLogin && strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
respawnConf.WriteString(fmt.Sprintf(" -n -l %s -o %s:%s", autologinBin, user, tty))
@ -370,3 +378,10 @@ func setupSSH(cfg *config.CloudConfig) error {
return os.MkdirAll("/var/run/sshd", 0644)
}
func istty(name string) bool {
if f, err := os.Open(fmt.Sprintf("/dev/%s", name)); err == nil {
return terminal.IsTerminal(int(f.Fd()))
}
return false
}