Skip to content

feat: integrate new agentexec pkg #15609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "sanity check lint rules"
This reverts commit 744693f.
  • Loading branch information
sreya committed Nov 25, 2024
commit 0ed12796e56aa4b393337bc7c960bf911394e728
10 changes: 5 additions & 5 deletions agent/agentssh/agentssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"cdr.dev/slog"

"github.com/coder/coder/v2/agent/agentexec"
"github.com/coder/coder/v2/agent/usershell"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/pty"
Expand Down Expand Up @@ -725,11 +726,10 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string)
}
}

// cmd, err := agentexec.PTYCommandContext(ctx, name, args...)
// if err != nil {
// return nil, xerrors.Errorf("pty command context: %w", err)
// }
cmd := pty.CommandContext(ctx, name, args...)
cmd, err := agentexec.PTYCommandContext(ctx, name, args...)
if err != nil {
return nil, xerrors.Errorf("pty command context: %w", err)
}
cmd.Dir = s.config.WorkingDirectory()

// If the metadata directory doesn't exist, we run the command
Expand Down
11 changes: 5 additions & 6 deletions agent/reconnectingpty/screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"net"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -334,21 +333,21 @@ func (rpty *screenReconnectingPTY) sendCommand(ctx context.Context, command stri
run := func() (bool, error) {
var stdout bytes.Buffer
//nolint:gosec
cmd := exec.CommandContext(ctx, "screen",
cmd, err := agentexec.CommandContext(ctx, "screen",
// -x targets an attached session.
"-x", rpty.id,
// -c is the flag for the config file.
"-c", rpty.configFile,
// -X runs a command in the matching session.
"-X", command,
)
// if err != nil {
// return false, xerrors.Errorf("command context: %w", err)
// }
if err != nil {
return false, xerrors.Errorf("command context: %w", err)
}
cmd.Env = append(rpty.command.Env, "TERM=xterm-256color")
cmd.Dir = rpty.command.Dir
cmd.Stdout = &stdout
err := cmd.Run()
err = cmd.Run()
if err == nil {
return true, nil
}
Expand Down
Loading