Add several TTY_SHARE_* session environment variables

Set these variables in the started child shell process:
- TTY_SHARE=1 to signal running inside a tty-share session
- TTY_SHARE_LOCAL_URL - contains the URL of the public session
- TTY_SHARE_PUBLIC_URL - contains the URL of the local session
pull/31/head v2.2.0
Vasile Popescu 3 years ago committed by Elis Popescu
parent fcefcdfb02
commit 6d477487d9

@ -125,14 +125,8 @@ Flags:
os.Exit(1)
}
ptyMaster := ptyMasterNew()
err := ptyMaster.Start(*commandName, strings.Fields(*commandArgs))
if err != nil {
log.Errorf("Cannot start the %s command: %s", *commandName, err.Error())
return
}
sessionID := "local"
sessionID := ""
publicURL := ""
if *publicSession {
proxy, err := proxy.NewProxyConnection(*listenAddress, *proxyServerAddress, *noTLS)
if err != nil {
@ -142,12 +136,35 @@ Flags:
go proxy.RunProxy()
sessionID = proxy.SessionID
fmt.Printf("public session: %s\n", proxy.PublicURL)
publicURL = proxy.PublicURL
defer proxy.Stop()
}
envVars := os.Environ()
envVars = append(envVars,
fmt.Sprintf("TTY_SHARE_LOCAL_URL=http://%s", *listenAddress),
fmt.Sprintf("TTY_SHARE=1", os.Getpid()),
)
if publicURL != "" {
envVars = append(envVars,
fmt.Sprintf("TTY_SHARE_PUBLIC_URL=%s", publicURL),
)
}
ptyMaster := ptyMasterNew()
err := ptyMaster.Start(*commandName, strings.Fields(*commandArgs), envVars)
if err != nil {
log.Errorf("Cannot start the %s command: %s", *commandName, err.Error())
return
}
// Display the session information to the user, before showing any output from the command.
// Wait until the user presses Enter
if publicURL != "" {
fmt.Printf("public session: %s\n", publicURL)
}
fmt.Printf("local session: http://%s/s/local/\n", *listenAddress)
fmt.Printf("Press Enter to continue!\n")
bufio.NewReader(os.Stdin).ReadString('\n')

@ -30,8 +30,9 @@ func isStdinTerminal() bool {
return terminal.IsTerminal(0)
}
func (pty *ptyMaster) Start(command string, args []string) (err error) {
func (pty *ptyMaster) Start(command string, args []string, envVars []string) (err error) {
pty.command = exec.Command(command, args...)
pty.command.Env = envVars
pty.ptyFile, err = ptyDevice.Start(pty.command)
if err != nil {

Loading…
Cancel
Save