Skip to content

Commit a752c89

Browse files
committed
Added hidden console allocation for transport processes on Windows.
This commit updates the process attributes and flags used for transport processes on Windows. Transport processes will now have a hidden console allocated by default. They were previously created without a console and would allocate one when required, creating a large number of pop-ups on Windows when using the Docker transport. This commit also takes the opportunity to reorganize the transport code and attributes. Fixes mutagen-io#233. Signed-off-by: Jacob Howard <[email protected]>
1 parent 3199de5 commit a752c89

File tree

24 files changed

+69
-71
lines changed

24 files changed

+69
-71
lines changed

cmd/mutagen/daemon/start_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package daemon
33
import (
44
"syscall"
55

6-
"github.com/mutagen-io/mutagen/pkg/process"
6+
"golang.org/x/sys/windows"
77
)
88

99
// daemonProcessAttributes are the process attributes to use for the daemon.
1010
var daemonProcessAttributes = &syscall.SysProcAttr{
11-
CreationFlags: process.DETACHED_PROCESS | syscall.CREATE_NEW_PROCESS_GROUP,
11+
CreationFlags: windows.DETACHED_PROCESS | windows.CREATE_NEW_PROCESS_GROUP,
1212
}

pkg/agent/transport/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package transport provides common functionality for agent transports.
2+
package transport

pkg/agent/transports/docker/transport.go renamed to pkg/agent/transport/docker/transport.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
"github.com/pkg/errors"
1212

1313
"github.com/mutagen-io/mutagen/pkg/agent"
14-
"github.com/mutagen-io/mutagen/pkg/agent/transports/ssh"
14+
"github.com/mutagen-io/mutagen/pkg/agent/transport"
15+
"github.com/mutagen-io/mutagen/pkg/agent/transport/ssh"
1516
"github.com/mutagen-io/mutagen/pkg/docker"
1617
"github.com/mutagen-io/mutagen/pkg/process"
1718
"github.com/mutagen-io/mutagen/pkg/prompting"
@@ -26,8 +27,8 @@ Hyper-V doesn't support copying files into running containers.
2627
2728
Would you like to continue? (yes/no)? `
2829

29-
// transport implements the agent.Transport interface using Docker.
30-
type transport struct {
30+
// dockerTransport implements the agent.Transport interface using Docker.
31+
type dockerTransport struct {
3132
// container is the target container name.
3233
container string
3334
// user is the container user under which agents should be invoked.
@@ -73,7 +74,7 @@ func NewTransport(container, user string, environment, parameters map[string]str
7374
}
7475

7576
// Success.
76-
return &transport{
77+
return &dockerTransport{
7778
container: container,
7879
user: user,
7980
environment: environment,
@@ -86,7 +87,7 @@ func NewTransport(container, user string, environment, parameters map[string]str
8687
// specification of the working directory inside the container, as well as an
8788
// override of the executing user. An empty user specification means to use the
8889
// username specified in the remote URL, if any.
89-
func (t *transport) command(command, workingDirectory, user string) (*exec.Cmd, error) {
90+
func (t *dockerTransport) command(command, workingDirectory, user string) (*exec.Cmd, error) {
9091
// Set up top-level command-line flags.
9192
var dockerArguments []string
9293
dockerArguments = append(dockerArguments, t.daemonConnectionFlags...)
@@ -125,8 +126,8 @@ func (t *transport) command(command, workingDirectory, user string) (*exec.Cmd,
125126
return nil, err
126127
}
127128

128-
// Force it to run detached.
129-
dockerCommand.SysProcAttr = process.DetachedProcessAttributes()
129+
// Set the process attributes.
130+
dockerCommand.SysProcAttr = transport.ProcessAttributes()
130131

131132
// Create a copy of the current environment.
132133
environment := os.Environ()
@@ -152,7 +153,7 @@ func (t *transport) command(command, workingDirectory, user string) (*exec.Cmd,
152153
// probeContainer ensures that the containerIsWindows and containerHomeDirectory
153154
// fields are populated. It is idempotent. If probing previously failed, probing
154155
// will simply return an error indicating the previous failure.
155-
func (t *transport) probeContainer() error {
156+
func (t *dockerTransport) probeContainer() error {
156157
// Watch for previous errors.
157158
if t.containerProbeError != nil {
158159
return errors.Wrap(t.containerProbeError, "previous container probing failed")
@@ -286,7 +287,7 @@ func (t *transport) probeContainer() error {
286287

287288
// changeContainerStatus stops or starts the container. It is required for
288289
// copying files on Windows when using Hyper-V.
289-
func (t *transport) changeContainerStatus(stop bool) error {
290+
func (t *dockerTransport) changeContainerStatus(stop bool) error {
290291
// Set up top-level command-line flags.
291292
var dockerArguments []string
292293
dockerArguments = append(dockerArguments, t.daemonConnectionFlags...)
@@ -304,8 +305,8 @@ func (t *transport) changeContainerStatus(stop bool) error {
304305
return errors.Wrap(err, "unable to set up Docker invocation")
305306
}
306307

307-
// Force it to run detached.
308-
dockerCommand.SysProcAttr = process.DetachedProcessAttributes()
308+
// Set the process attributes.
309+
dockerCommand.SysProcAttr = transport.ProcessAttributes()
309310

310311
// Create a copy of the current environment.
311312
environment := os.Environ()
@@ -329,7 +330,7 @@ func (t *transport) changeContainerStatus(stop bool) error {
329330
}
330331

331332
// Copy implements the Copy method of agent.Transport.
332-
func (t *transport) Copy(localPath, remoteName string) error {
333+
func (t *dockerTransport) Copy(localPath, remoteName string) error {
333334
// Ensure that the container has been probed.
334335
if err := t.probeContainer(); err != nil {
335336
return errors.Wrap(err, "unable to probe container")
@@ -390,8 +391,8 @@ func (t *transport) Copy(localPath, remoteName string) error {
390391
return errors.Wrap(err, "unable to set up Docker invocation")
391392
}
392393

393-
// Force it to run detached.
394-
dockerCommand.SysProcAttr = process.DetachedProcessAttributes()
394+
// Set the process attributes.
395+
dockerCommand.SysProcAttr = transport.ProcessAttributes()
395396

396397
// Create a copy of the current environment.
397398
environment := os.Environ()
@@ -464,7 +465,7 @@ func (t *transport) Copy(localPath, remoteName string) error {
464465
}
465466

466467
// Command implements the Command method of agent.Transport.
467-
func (t *transport) Command(command string) (*exec.Cmd, error) {
468+
func (t *dockerTransport) Command(command string) (*exec.Cmd, error) {
468469
// Ensure that the container has been probed.
469470
if err := t.probeContainer(); err != nil {
470471
return nil, errors.Wrap(err, "unable to probe container")
@@ -475,7 +476,7 @@ func (t *transport) Command(command string) (*exec.Cmd, error) {
475476
}
476477

477478
// ClassifyError implements the ClassifyError method of agent.Transport.
478-
func (t *transport) ClassifyError(processState *os.ProcessState, errorOutput string) (bool, bool, error) {
479+
func (t *dockerTransport) ClassifyError(processState *os.ProcessState, errorOutput string) (bool, bool, error) {
479480
// Ensure that the container has been probed.
480481
if err := t.probeContainer(); err != nil {
481482
return false, false, errors.Wrap(err, "unable to probe container")

pkg/process/attributes_posix.go renamed to pkg/agent/transport/process_posix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
// TODO: Figure out what to do for Plan 9. It doesn't support Setsid.
44

5-
package process
5+
package transport
66

77
import (
88
"syscall"
99
)
1010

11-
// DetachedProcessAttributes returns the process attributes to use for starting
12-
// detached processes.
13-
func DetachedProcessAttributes() *syscall.SysProcAttr {
11+
// ProcessAttributes returns the process attributes to use for starting
12+
// transport processes from the daemon.
13+
func ProcessAttributes() *syscall.SysProcAttr {
1414
return &syscall.SysProcAttr{
1515
// There's also a Noctty field, but it only detaches standard input from
1616
// the controlling terminal (not standard output or error), and if

pkg/agent/transport/process_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package transport
2+
3+
import (
4+
"testing"
5+
)
6+
7+
// TestProcessAttributes tests ProcessAttributes.
8+
func TestProcessAttributes(t *testing.T) {
9+
if ProcessAttributes() == nil {
10+
t.Error("nil transport process attributes returned")
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package transport
2+
3+
import (
4+
"syscall"
5+
6+
"golang.org/x/sys/windows"
7+
)
8+
9+
// ProcessAttributes returns the process attributes to use for starting
10+
// transport processes from the daemon.
11+
func ProcessAttributes() *syscall.SysProcAttr {
12+
return &syscall.SysProcAttr{
13+
HideWindow: true,
14+
CreationFlags: windows.CREATE_NEW_CONSOLE,
15+
}
16+
}

0 commit comments

Comments
 (0)