more runcmd logging

This commit is contained in:
Pavel Vorobyov
2019-09-27 15:36:20 +03:00
parent 37b767d418
commit e509bffcb5
2 changed files with 14 additions and 2 deletions

View File

@@ -26,12 +26,14 @@ func (w *Worker) runcmd(task *Task) int {
ptmx, err := pty.Start(cmd)
if err != nil {
log.Debugf("WRK[%d]: Error creating ptmx: %v", w.id, err)
return ErrTerminalError
}
defer ptmx.Close()
fd, err := poller.NewFD(int(ptmx.Fd()))
if err != nil {
log.Debugf("WRK[%d]: Error creating poller FD: %v", w.id, err)
return ErrTerminalError
}
defer fd.Close()
@@ -64,6 +66,7 @@ execLoop:
if err != nil {
if err != poller.ErrTimeout {
// EOF, done
log.Debugf("WRK[%d]: error reading process output: %v", w.id, err)
break
} else {
continue
@@ -82,7 +85,10 @@ execLoop:
// Trying to find Password prompt in first 5 chunks of data from server
if msgCount < 5 {
if !passwordSent && exPasswdPrompt.Match(chunk) {
ptmx.Write([]byte(password + "\n"))
_, err := ptmx.Write([]byte(password + "\n"))
if err != nil {
log.Debugf("WRK[%d]: Error sending password: %v", w.id, err)
}
passwordSent = true
shouldSkipEcho = true
continue
@@ -120,7 +126,10 @@ execLoop:
exitCode := 0
if taskForceStopped {
cmd.Process.Kill()
err = cmd.Process.Kill()
if err != nil {
log.Debugf("WRK[%d]: Error killing the process: %v", w.id, err)
}
exitCode = ErrForceStop
log.Debugf("WRK[%d]: Task on %s was force stopped", w.id, task.Hostname)
}