mirror of https://github.com/liamg/aminal.git
Add correct handling of attaching to child console errors (#239)
This commit is contained in:
parent
4ec83c54a4
commit
a68b693bfd
|
@ -7,6 +7,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
"github.com/MaxRis/w32"
|
"github.com/MaxRis/w32"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -135,15 +136,20 @@ func (pty *winConPty) Close() error {
|
||||||
|
|
||||||
func (pty *winConPty) CreateGuestProcess(imagePath string) (Process, error) {
|
func (pty *winConPty) CreateGuestProcess(imagePath string) (Process, error) {
|
||||||
process, err := createPtyChildProcess(imagePath, pty.hcon)
|
process, err := createPtyChildProcess(imagePath, pty.hcon)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if err == nil {
|
err = setupChildConsole(C.DWORD(process.processID), C.STD_OUTPUT_HANDLE, C.ENABLE_PROCESSED_OUTPUT|C.ENABLE_WRAP_AT_EOL_OUTPUT)
|
||||||
setupChildConsole(C.DWORD(process.processID), C.STD_OUTPUT_HANDLE, C.ENABLE_PROCESSED_OUTPUT|C.ENABLE_WRAP_AT_EOL_OUTPUT)
|
if err != nil {
|
||||||
|
process.Close()
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return process, err
|
return process, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupChildConsole(processID C.DWORD, nStdHandle C.DWORD, mode uint) bool {
|
func setupChildConsole(processID C.DWORD, nStdHandle C.DWORD, mode uint) error {
|
||||||
C.FreeConsole()
|
C.FreeConsole()
|
||||||
defer C.AttachConsole(^C.DWORD(0)) // attach to parent process console
|
defer C.AttachConsole(^C.DWORD(0)) // attach to parent process console
|
||||||
|
|
||||||
|
@ -158,7 +164,7 @@ func setupChildConsole(processID C.DWORD, nStdHandle C.DWORD, mode uint) bool {
|
||||||
}
|
}
|
||||||
lastError := C.GetLastError()
|
lastError := C.GetLastError()
|
||||||
if lastError != C.ERROR_GEN_FAILURE || count <= 0 {
|
if lastError != C.ERROR_GEN_FAILURE || count <= 0 {
|
||||||
return false
|
return fmt.Errorf("Was not able to attach to the child prosess' console")
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Millisecond * time.Duration(waitStepMilliSeconds))
|
time.Sleep(time.Millisecond * time.Duration(waitStepMilliSeconds))
|
||||||
|
@ -169,7 +175,7 @@ func setupChildConsole(processID C.DWORD, nStdHandle C.DWORD, mode uint) bool {
|
||||||
C.SetConsoleMode(h, C.DWORD(mode))
|
C.SetConsoleMode(h, C.DWORD(mode))
|
||||||
C.FreeConsole()
|
C.FreeConsole()
|
||||||
|
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pty *winConPty) Resize(x, y int) error {
|
func (pty *winConPty) Resize(x, y int) error {
|
||||||
|
|
Loading…
Reference in New Issue