Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0ed107

Browse files
authored
fix: Add command to reconnecting PTY (#1860)
Thisfixes#1708 and opens the door for PTYs to executenon-shell commands!
1 parent6052607 commitd0ed107

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

‎agent/agent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
456456

457457
// The ID format is referenced in conn.go.
458458
// <uuid>:<height>:<width>
459-
idParts:=strings.Split(rawID,":")
460-
iflen(idParts)!=3 {
459+
idParts:=strings.SplitN(rawID,":",4)
460+
iflen(idParts)!=4 {
461461
a.logger.Warn(ctx,"client sent invalid id format",slog.F("raw-id",rawID))
462462
return
463463
}
@@ -489,7 +489,7 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
489489
}
490490
}else {
491491
// Empty command will default to the users shell!
492-
cmd,err:=a.createCommand(ctx,"",nil)
492+
cmd,err:=a.createCommand(ctx,idParts[3],nil)
493493
iferr!=nil {
494494
a.logger.Warn(ctx,"create reconnecting pty command",slog.Error(err))
495495
return

‎agent/agent_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func TestAgent(t *testing.T) {
221221

222222
conn:=setupAgent(t, agent.Metadata{},0)
223223
id:=uuid.NewString()
224-
netConn,err:=conn.ReconnectingPTY(id,100,100)
224+
netConn,err:=conn.ReconnectingPTY(id,100,100,"/bin/bash")
225225
require.NoError(t,err)
226226
bufRead:=bufio.NewReader(netConn)
227227

@@ -259,7 +259,7 @@ func TestAgent(t *testing.T) {
259259
expectLine(matchEchoOutput)
260260

261261
_=netConn.Close()
262-
netConn,err=conn.ReconnectingPTY(id,100,100)
262+
netConn,err=conn.ReconnectingPTY(id,100,100,"/bin/bash")
263263
require.NoError(t,err)
264264
bufRead=bufio.NewReader(netConn)
265265

‎agent/conn.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ type Conn struct {
3434

3535
// ReconnectingPTY returns a connection serving a TTY that can
3636
// be reconnected to via ID.
37-
func (c*Conn)ReconnectingPTY(idstring,height,widthuint16) (net.Conn,error) {
38-
channel,err:=c.CreateChannel(context.Background(),fmt.Sprintf("%s:%d:%d",id,height,width),&peer.ChannelOptions{
37+
//
38+
// The command is optional and defaults to start a shell.
39+
func (c*Conn)ReconnectingPTY(idstring,height,widthuint16,commandstring) (net.Conn,error) {
40+
channel,err:=c.CreateChannel(context.Background(),fmt.Sprintf("%s:%d:%d:%s",id,height,width,command),&peer.ChannelOptions{
3941
Protocol:ProtocolReconnectingPTY,
4042
})
4143
iferr!=nil {

‎coderd/workspaceagents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
381381
return
382382
}
383383
deferagentConn.Close()
384-
ptNetConn,err:=agentConn.ReconnectingPTY(reconnect.String(),uint16(height),uint16(width))
384+
ptNetConn,err:=agentConn.ReconnectingPTY(reconnect.String(),uint16(height),uint16(width),"")
385385
iferr!=nil {
386386
_=conn.Close(websocket.StatusInternalError,httpapi.WebsocketCloseSprintf("dial: %s",err))
387387
return

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp