Skip to content

Commit 32bb304

Browse files
committed
client/cordium - fix notify ctx for windows
1 parent 68c09b3 commit 32bb304

3 files changed

Lines changed: 69 additions & 5 deletions

File tree

client/cordium/commands/terminal/cmd.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"io"
2323
"os"
2424
"os/signal"
25-
"syscall"
2625
"time"
2726

2827
pb "github.com/octelium/octelium/apis/main/cordiumv1"
@@ -80,7 +79,7 @@ func doCmd(cmd *cobra.Command, args []string) error {
8079
}
8180

8281
func DoCmdTerminal(ctx context.Context, conn *grpc.ClientConn, wsName string) error {
83-
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
82+
ctx, cancel := notifyTerminalExitContext(ctx)
8483
defer cancel()
8584

8685
c := pb.NewWorkspaceServiceClient(conn)
@@ -118,10 +117,10 @@ func DoCmdTerminal(ctx context.Context, conn *grpc.ClientConn, wsName string) er
118117
}
119118

120119
sigCh := make(chan os.Signal, 1)
121-
signal.Notify(sigCh, syscall.SIGWINCH)
120+
notifyWindowSizeChange(sigCh)
121+
defer signal.Stop(sigCh)
122122

123123
go func(ctx context.Context) {
124-
125124
for {
126125
select {
127126
case <-ctx.Done():
@@ -144,7 +143,6 @@ func DoCmdTerminal(ctx context.Context, conn *grpc.ClientConn, wsName string) er
144143
}
145144
}
146145
}
147-
148146
}(ctx)
149147

150148
go func(ctx context.Context) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//go:build !windows
2+
3+
/*
4+
* Copyright Octelium Labs, LLC. All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package terminal
20+
21+
import (
22+
"context"
23+
"os"
24+
"os/signal"
25+
"syscall"
26+
)
27+
28+
func notifyTerminalExitContext(ctx context.Context) (context.Context, context.CancelFunc) {
29+
return signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)
30+
}
31+
32+
func notifyWindowSizeChange(ch chan<- os.Signal) {
33+
signal.Notify(ch, syscall.SIGWINCH)
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//go:build windows
2+
3+
/*
4+
* Copyright Octelium Labs, LLC. All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package terminal
20+
21+
import (
22+
"context"
23+
"os"
24+
"os/signal"
25+
)
26+
27+
func notifyTerminalExitContext(ctx context.Context) (context.Context, context.CancelFunc) {
28+
return signal.NotifyContext(ctx, os.Interrupt)
29+
}
30+
31+
func notifyWindowSizeChange(ch chan<- os.Signal) {
32+
}

0 commit comments

Comments
 (0)