-
Notifications
You must be signed in to change notification settings - Fork 29
Generalize console control #623
Generalize console control #623
Conversation
07fab6f
to
122dce0
Compare
So this handles the case when the plugin's API prompts for something, right? Then having control of the console prior to a method invocation would make sense. |
Yes. |
122dce0
to
b34b32a
Compare
Ok, I think this works better now. |
be84dba
to
7568973
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most comments are about moving err :=
stuff to a separate line. I think only one asks a legitimate question. Otherwise, this LGTM.
signal.Notify(sigCh, syscall.SIGINT) | ||
cancelCtx, cancel := context.WithCancel(ctx) | ||
go func() { | ||
<-sigCh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't block forever, will it? Guessing the Reset
below prevents that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it might. I can probably do something about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be addressed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just close sigCh
in a defer? You'll still need to call the cancel func either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, didn't think of it.
7568973
to
e471da1
Compare
Sometimes a plugin needs control of the console for a prompt it doesn't make directly. Get control before calling all primitives that take a context (as a proxy for potential network activity or execs). This isn't entirely safe. If it's backgrounded and prompts for input it may not exit cleanly. Using `plugin.Prompt` guards against this issue. Fixes puppetlabs-toy-chest#297. Signed-off-by: Michael Smith <[email protected]>
e471da1
to
9219138
Compare
When `wash` is run, it starts a shell as a child process where all the action happens. It then stays running as a daemon to handle Wash-specific requests through FUSE and the socket API. However if it needs to prompt for input, it has trouble because it's TTY is not the same as the one handling input (the child shell). We previously addressed that by temporarily transferring control of input to the Wash daemon, but that had some problems - it only worked when a plugin requested input using Wash's helper - if the process that triggered the plugin activity tried to do something with stdin - like MacVim appears to on startup - it would fail Reparent the Wash daemon to have a new session under the new shell so they share the same TTY. Prompts for input now work wherever they're triggered from. MacVim still behaves a little strangely if you get a prompt when opening it, but I'm not sure what to do about it. Fixes puppetlabs-toy-chest#623. Signed-off-by: Michael Smith <[email protected]>
When `wash` is run, it starts a shell as a child process where all the action happens. It then stays running as a daemon to handle Wash-specific requests through FUSE and the socket API. However if it needs to prompt for input, it has trouble because it's TTY is not the same as the one handling input (the child shell). We previously addressed that by temporarily transferring control of input to the Wash daemon, but that had some problems - it only worked when a plugin requested input using Wash's helper - if the process that triggered the plugin activity tried to do something with stdin - like MacVim appears to on startup - it would fail Reparent the Wash daemon to have a new session under the new shell so they share the same TTY. Prompts for input now work wherever they're triggered from. MacVim still behaves a little strangely if you get a prompt when opening it, but I'm not sure what to do about it. Fixes puppetlabs-toy-chest#623. Signed-off-by: Michael Smith <[email protected]>
When `wash` is run, it starts a shell as a child process where all the action happens. It then stays running as a daemon to handle Wash-specific requests through FUSE and the socket API. However if it needs to prompt for input, it has trouble because it's TTY is not the same as the one handling input (the child shell). We previously addressed that by temporarily transferring control of input to the Wash daemon, but that had some problems - it only worked when a plugin requested input using Wash's helper - if the process that triggered the plugin activity tried to do something with stdin - like MacVim appears to on startup - it would fail Reparent the Wash daemon to have a new session under the new shell so they share the same TTY. Prompts for input now work wherever they're triggered from. MacVim still behaves a little strangely if you get a prompt when opening it, but I'm not sure what to do about it. Fixes puppetlabs-toy-chest#623. Signed-off-by: Michael Smith <[email protected]>
When `wash` is run, it starts a shell as a child process where all the action happens. It then stays running as a daemon to handle Wash-specific requests through FUSE and the socket API. However if it needs to prompt for input, it has trouble because it's TTY is not the same as the one handling input (the child shell). We previously addressed that by temporarily transferring control of input to the Wash daemon, but that had some problems - it only worked when a plugin requested input using Wash's helper - if the process that triggered the plugin activity tried to do something with stdin - like MacVim appears to on startup - it would fail Reparent the Wash daemon to have a new session under the new shell so they share the same TTY. Prompts for input now work wherever they're triggered from. MacVim still behaves a little strangely if you get a prompt when opening it, but I'm not sure what to do about it. Fixes puppetlabs-toy-chest#623. Signed-off-by: Michael Smith <[email protected]>
Sometimes a plugin needs control of the console for a prompt it doesn't make directly. Get control before calling all primitives that take a context (as a proxy for potential network activity or execs).
This isn't entirely safe. If it's backgrounded and prompts for input it may not exit cleanly. Using
plugin.Prompt
guards against this issue.Fixes #297.
Signed-off-by: Michael Smith [email protected]