From 45f8f611035e6a5cf208864e2f2384afb7fa199b Mon Sep 17 00:00:00 2001 From: Iwasaki Yudai Date: Sun, 20 Aug 2017 13:39:06 +0900 Subject: [PATCH] Fix option handling of close signal --- backend/localcommand/factory.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/localcommand/factory.go b/backend/localcommand/factory.go index 146df36..11810ed 100644 --- a/backend/localcommand/factory.go +++ b/backend/localcommand/factory.go @@ -2,6 +2,7 @@ package localcommand import ( "syscall" + "time" "github.com/yudai/gotty/server" ) @@ -15,13 +16,20 @@ type Factory struct { command string argv []string options *Options + opts []Option } 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{ command: command, argv: argv, options: options, + opts: opts, }, nil } @@ -35,10 +43,6 @@ func (factory *Factory) New(params map[string][]string) (server.Slave, error) { if params["arg"] != nil && len(params["arg"]) > 0 { argv = append(argv, params["arg"]...) } - return New( - factory.command, - argv, - WithCloseSignal(syscall.Signal(factory.options.CloseSignal)), - WithCloseSignal(syscall.Signal(factory.options.CloseTimeout)), - ) + + return New(factory.command, argv, factory.opts...) }