Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore(agent/agentscripts): log command cancellation #16324

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 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion agent/agentscripts/agentscripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
cmd = cmdPty.AsExec()
cmd.SysProcAttr = cmdSysProcAttr()
cmd.WaitDelay = 10 * time.Second
cmd.Cancel = cmdCancel(cmd)
cmd.Cancel = cmdCancel(ctx, logger, cmd)

// Expose env vars that can be used in the script for storing data
// and binaries. In the future, we may want to expose more env vars
Expand Down
6 changes: 5 additions & 1 deletion agent/agentscripts/agentscripts_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
package agentscripts

import (
"context"
"os/exec"
"syscall"

"cdr.dev/slog"
)

func cmdSysProcAttr() *syscall.SysProcAttr {
Expand All @@ -13,8 +16,9 @@ func cmdSysProcAttr() *syscall.SysProcAttr {
}
}

func cmdCancel(cmd *exec.Cmd) func() error {
func cmdCancel(ctx context.Context, logger slog.Logger, cmd *exec.Cmd) func() error {
return func() error {
logger.Debug(ctx, "cmdCancel: sending SIGHUP to process and children", slog.F("pid", cmd.Process.Pid))
return syscall.Kill(-cmd.Process.Pid, syscall.SIGHUP)
}
}
6 changes: 5 additions & 1 deletion agent/agentscripts/agentscripts_windows.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package agentscripts

import (
"context"
"os"
"os/exec"
"syscall"

"cdr.dev/slog"
)

func cmdSysProcAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{}
}

func cmdCancel(cmd *exec.Cmd) func() error {
func cmdCancel(ctx context.Context, logger slog.Logger, cmd *exec.Cmd) func() error {
return func() error {
logger.Debug(ctx, "cmdCancel: sending interrupt to process", slog.F("pid", cmd.Process.Pid))
return cmd.Process.Signal(os.Interrupt)
}
}
Loading