Commit 45f8f611 by Iwasaki Yudai

Fix option handling of close signal

1 parent 56e9b891
Showing with 10 additions and 6 deletions
...@@ -2,6 +2,7 @@ package localcommand ...@@ -2,6 +2,7 @@ package localcommand
import ( import (
"syscall" "syscall"
"time"
"github.com/yudai/gotty/server" "github.com/yudai/gotty/server"
) )
...@@ -15,13 +16,20 @@ type Factory struct { ...@@ -15,13 +16,20 @@ type Factory struct {
command string command string
argv []string argv []string
options *Options options *Options
opts []Option
} }
func NewFactory(command string, argv []string, options *Options) (*Factory, error) { func NewFactory(command string, argv []string, options *Options) (*Factory, error) {
opts := []Option{WithCloseSignal(syscall.Signal(options.CloseSignal))}
if options.CloseTimeout >= 0 {
opts = append(opts, WithCloseTimeout(time.Duration(options.CloseTimeout)*time.Second))
}
return &Factory{ return &Factory{
command: command, command: command,
argv: argv, argv: argv,
options: options, options: options,
opts: opts,
}, nil }, nil
} }
...@@ -35,10 +43,6 @@ func (factory *Factory) New(params map[string][]string) (server.Slave, error) { ...@@ -35,10 +43,6 @@ func (factory *Factory) New(params map[string][]string) (server.Slave, error) {
if params["arg"] != nil && len(params["arg"]) > 0 { if params["arg"] != nil && len(params["arg"]) > 0 {
argv = append(argv, params["arg"]...) argv = append(argv, params["arg"]...)
} }
return New(
factory.command, return New(factory.command, argv, factory.opts...)
argv,
WithCloseSignal(syscall.Signal(factory.options.CloseSignal)),
WithCloseSignal(syscall.Signal(factory.options.CloseTimeout)),
)
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!