Explorar o código

ssh system commands: wait on write from command out to network

we only need to wait for the write from the local command to
the ssh channel. There is no need to wait for the write from ssh
channel to the local command stdin
Nicola Murino %!s(int64=5) %!d(string=hai) anos
pai
achega
bc844105b2
Modificáronse 2 ficheiros con 5 adicións e 7 borrados
  1. 1 1
      sftpd/sftpd.go
  2. 4 6
      sftpd/ssh_cmd.go

+ 1 - 1
sftpd/sftpd.go

@@ -424,7 +424,7 @@ func executeAction(operation, username, path, target, sshCmd string) error {
 		if _, err = os.Stat(actions.Command); err == nil {
 		if _, err = os.Stat(actions.Command); err == nil {
 			command := exec.Command(actions.Command, operation, username, path, target, sshCmd)
 			command := exec.Command(actions.Command, operation, username, path, target, sshCmd)
 			err = command.Start()
 			err = command.Start()
-			logger.Debug(logSender, "", "start command %#v with arguments: %v, %v, %v, %v %v, error: %v",
+			logger.Debug(logSender, "", "start command %#v with arguments: %#v, %#v, %#v, %#v, %#v, error: %v",
 				actions.Command, operation, username, path, target, sshCmd, err)
 				actions.Command, operation, username, path, target, sshCmd, err)
 			if err == nil {
 			if err == nil {
 				// we are in a goroutine but we don't want to block here, this way we can send the
 				// we are in a goroutine but we don't want to block here, this way we can send the

+ 4 - 6
sftpd/ssh_cmd.go

@@ -174,8 +174,7 @@ func (c *sshCommand) executeSystemCommand(command systemCommand) error {
 		c.connection.channel.Close()
 		c.connection.channel.Close()
 	}
 	}
 	var once sync.Once
 	var once sync.Once
-	var wg sync.WaitGroup
-	wg.Add(2)
+	commandResponse := make(chan bool)
 
 
 	go func() {
 	go func() {
 		defer stdin.Close()
 		defer stdin.Close()
@@ -207,7 +206,6 @@ func (c *sshCommand) executeSystemCommand(command systemCommand) error {
 		if e != nil {
 		if e != nil {
 			once.Do(closeCmdOnError)
 			once.Do(closeCmdOnError)
 		}
 		}
-		wg.Done()
 	}()
 	}()
 
 
 	go func() {
 	go func() {
@@ -235,7 +233,7 @@ func (c *sshCommand) executeSystemCommand(command systemCommand) error {
 		if e != nil {
 		if e != nil {
 			once.Do(closeCmdOnError)
 			once.Do(closeCmdOnError)
 		}
 		}
-		wg.Done()
+		commandResponse <- true
 	}()
 	}()
 
 
 	go func() {
 	go func() {
@@ -265,7 +263,7 @@ func (c *sshCommand) executeSystemCommand(command systemCommand) error {
 		}
 		}
 	}()
 	}()
 
 
-	wg.Wait()
+	<-commandResponse
 	err = command.cmd.Wait()
 	err = command.cmd.Wait()
 	c.sendExitStatus(err)
 	c.sendExitStatus(err)
 	c.rescanHomeDir()
 	c.rescanHomeDir()
@@ -290,7 +288,7 @@ func (c *sshCommand) getSystemCommand() (systemCommand, error) {
 		args = args[:len(args)-1]
 		args = args[:len(args)-1]
 		args = append(args, path)
 		args = append(args, path)
 	}
 	}
-	c.connection.Log(logger.LevelDebug, logSenderSSH, "new system command: %v, with args: %v path: %v", c.command, args, path)
+	c.connection.Log(logger.LevelDebug, logSenderSSH, "new system command %#v, with args: %v path: %v", c.command, args, path)
 	cmd := exec.Command(c.command, args...)
 	cmd := exec.Command(c.command, args...)
 	uid := c.connection.User.GetUID()
 	uid := c.connection.User.GetUID()
 	gid := c.connection.User.GetGID()
 	gid := c.connection.User.GetGID()