Skip to content

Commit 291cbd6

Browse files
authored
Merge pull request #2617 from alexandear/refactor/channel-direction
Refactor to use directional error channels
2 parents cd12dbe + 1e34d59 commit 291cbd6

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

pkg/hostagent/hostagent.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
421421
return a.startRoutinesAndWait(ctx, errCh)
422422
}
423423

424-
func (a *HostAgent) startRoutinesAndWait(ctx context.Context, errCh chan error) error {
424+
func (a *HostAgent) startRoutinesAndWait(ctx context.Context, errCh <-chan error) error {
425425
stBase := events.Status{
426426
SSHLocalPort: a.sshLocalPort,
427427
}

pkg/wsl2/vm_windows.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func stopVM(ctx context.Context, distroName string) error {
6767
var limaBoot string
6868

6969
// provisionVM starts Lima's boot process inside an already imported VM.
70-
func provisionVM(ctx context.Context, instanceDir, instanceName, distroName string, errCh *chan error) error {
70+
func provisionVM(ctx context.Context, instanceDir, instanceName, distroName string, errCh chan<- error) error {
7171
ciDataPath := filepath.Join(instanceDir, filenames.CIDataISODir)
7272
m := map[string]string{
7373
"CIDataPath": ciDataPath,
@@ -120,7 +120,7 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
120120
os.RemoveAll(limaBootFileWinPath)
121121
logrus.Debugf("%v: %q", cmd.Args, string(out))
122122
if err != nil {
123-
*errCh <- fmt.Errorf(
123+
errCh <- fmt.Errorf(
124124
"error running wslCommand that executes boot.sh (%v): %w, "+
125125
"check /var/log/lima-init.log for more details (out=%q)", cmd.Args, err, string(out))
126126
}
@@ -139,7 +139,7 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
139139
}
140140

141141
// keepAlive runs a background process which in order to keep the WSL2 VM running in the background after launch.
142-
func keepAlive(ctx context.Context, distroName string, errCh *chan error) {
142+
func keepAlive(ctx context.Context, distroName string, errCh chan<- error) {
143143
keepAliveCmd := exec.CommandContext(
144144
ctx,
145145
"wsl.exe",
@@ -152,7 +152,7 @@ func keepAlive(ctx context.Context, distroName string, errCh *chan error) {
152152

153153
go func() {
154154
if err := keepAliveCmd.Run(); err != nil {
155-
*errCh <- fmt.Errorf(
155+
errCh <- fmt.Errorf(
156156
"error running wsl keepAlive command: %w", err)
157157
}
158158
}()

pkg/wsl2/wsl_driver_windows.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ func (l *LimaWslDriver) Start(ctx context.Context) (chan error, error) {
131131
l.BaseDriver.Instance.Dir,
132132
l.BaseDriver.Instance.Name,
133133
distroName,
134-
&errCh,
134+
errCh,
135135
); err != nil {
136136
return nil, err
137137
}
138138

139-
keepAlive(ctx, distroName, &errCh)
139+
keepAlive(ctx, distroName, errCh)
140140

141141
return errCh, err
142142
}

0 commit comments

Comments
 (0)