Helper functions for SpawnShellServer
()
| 1251 | |
| 1252 | // Helper functions for SpawnShellServer |
| 1253 | func (ghost *Ghost) setupShellEnvironment() { |
| 1254 | // Execute shell command from HOME directory |
| 1255 | home := os.Getenv("HOME") |
| 1256 | if home == "" { |
| 1257 | home = "/tmp" |
| 1258 | } |
| 1259 | if err := os.Chdir(home); err != nil { |
| 1260 | log.Printf("Failed to change directory to %s: %v", home, err) |
| 1261 | } |
| 1262 | |
| 1263 | // Add ghost executable to PATH |
| 1264 | exePath, err := os.Executable() |
| 1265 | if err == nil { |
| 1266 | os.Setenv("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), |
| 1267 | filepath.Dir(exePath))) |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | func (ghost *Ghost) setupShellCommand(stopConn chan struct{}) (*exec.Cmd, io.WriteCloser, error) { |
| 1272 | cmd := exec.Command(defaultShell, "-c", ghost.shellCommand) |