mirror of
https://github.com/rancher/os.git
synced 2025-08-07 09:44:19 +00:00
Check the tty before adding to respawn.conf
This commit is contained in:
parent
1a2c711d1e
commit
7c13d76066
@ -11,9 +11,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
|
||||||
"github.com/rancher/os/cmd/cloudinitexecute"
|
"github.com/rancher/os/cmd/cloudinitexecute"
|
||||||
"github.com/rancher/os/config"
|
"github.com/rancher/os/config"
|
||||||
"github.com/rancher/os/config/cmdline"
|
"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++ {
|
for i := 1; i < 7; i++ {
|
||||||
tty := fmt.Sprintf("tty%d", i)
|
tty := fmt.Sprintf("tty%d", i)
|
||||||
|
if !istty(tty) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
respawnConf.WriteString(gettyCmd)
|
respawnConf.WriteString(gettyCmd)
|
||||||
if allowAutoLogin && strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !istty(tty) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
respawnConf.WriteString(gettyCmd)
|
respawnConf.WriteString(gettyCmd)
|
||||||
if allowAutoLogin && strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
|
if allowAutoLogin && strings.Contains(cmdline, fmt.Sprintf("rancher.autologin=%s", tty)) {
|
||||||
respawnConf.WriteString(fmt.Sprintf(" -n -l %s -o %s:%s", autologinBin, user, 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)
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user