mirror of
https://github.com/kemko/xc.git
synced 2026-01-01 15:55:43 +03:00
threadsafe acquiring pty
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -21,6 +22,7 @@ var (
|
||||
currentRemoteTmpdir string
|
||||
currentDebug bool
|
||||
outputFile *os.File
|
||||
ptyLock *sync.Mutex
|
||||
|
||||
noneInterpreter string
|
||||
suInterpreter string
|
||||
@@ -30,6 +32,7 @@ var (
|
||||
// Initialize initializes new execution pool
|
||||
func Initialize(numThreads int, username string) {
|
||||
pool = NewPool(numThreads)
|
||||
ptyLock = new(sync.Mutex)
|
||||
SetUser(username)
|
||||
SetPassword("")
|
||||
SetRaise(RTNone)
|
||||
|
||||
@@ -19,24 +19,32 @@ func (w *Worker) runcmd(task *Task) int {
|
||||
n int
|
||||
password string
|
||||
passwordSent bool
|
||||
ptmx *os.File
|
||||
fd *poller.FD
|
||||
)
|
||||
|
||||
cmd := createSSHCmd(task.Hostname, task.Cmd)
|
||||
cmd.Env = append(os.Environ(), environment...)
|
||||
|
||||
ptmx, err := pty.Start(cmd)
|
||||
// threadsafe acquiring necessary file descriptors
|
||||
ptyLock.Lock()
|
||||
ptmx, err = pty.Start(cmd)
|
||||
if err != nil {
|
||||
log.Debugf("WRK[%d]: Error creating ptmx: %v", w.id, err)
|
||||
ptyLock.Unlock()
|
||||
return ErrTerminalError
|
||||
}
|
||||
defer ptmx.Close()
|
||||
|
||||
fd, err := poller.NewFD(int(ptmx.Fd()))
|
||||
fd, err = poller.NewFD(int(ptmx.Fd()))
|
||||
if err != nil {
|
||||
log.Debugf("WRK[%d]: Error creating poller FD: %v", w.id, err)
|
||||
ptyLock.Unlock()
|
||||
return ErrTerminalError
|
||||
}
|
||||
defer fd.Close()
|
||||
ptyLock.Unlock()
|
||||
// threadsafe acquiring necessary file descriptors ends
|
||||
|
||||
buf := make([]byte, bufferSize)
|
||||
taskForceStopped := false
|
||||
|
||||
Reference in New Issue
Block a user