Skip to content

feat(agent/agentssh): handle session signals #10842

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
Nov 23, 2023
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
fixes
  • Loading branch information
mafredri committed Nov 22, 2023
commit 15587dc1c5c074e947247dd0e4a4cfed6ca119b4
4 changes: 2 additions & 2 deletions agent/agentssh/agentssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ func (s *Server) handleSignal(logger slog.Logger, ssig ssh.Signal, signaler inte
ctx := context.Background()
sig := osSignalFrom(ssig)
logger = logger.With(slog.F("ssh_signal", ssig), slog.F("signal", sig.String()))
logger.Info(ctx, "received signal")
logger.Info(ctx, "received signal from client")
err := signaler.Signal(sig)
if err != nil {
logger.Warn(ctx, "signal failed", slog.Error(err))
logger.Warn(ctx, "signaling the process failed", slog.Error(err))
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "signal").Add(1)
}
}
Expand Down
7 changes: 6 additions & 1 deletion agent/agentssh/agentssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestNewServer_CloseActiveConnections(t *testing.T) {
defer wg.Done()
c := sshClient(t, ln.Addr().String())
sess, err := c.NewSession()
require.NoError(t, err)
assert.NoError(t, err)
sess.Stdin = pty.Input()
sess.Stdout = pty.Output()
sess.Stderr = pty.Output()
Expand Down Expand Up @@ -259,13 +259,18 @@ func TestNewServer_Signal(t *testing.T) {

c := sshClient(t, ln.Addr().String())

pty := ptytest.New(t)

sess, err := c.NewSession()
require.NoError(t, err)
r, err := sess.StdoutPipe()
require.NoError(t, err)

// Note, we request pty but don't use ptytest here because we can't
// easily test for no text before EOF.
sess.Stdin = pty.Input()
sess.Stderr = pty.Output()

err = sess.RequestPty("xterm", 80, 80, nil)
require.NoError(t, err)

Expand Down
3 changes: 1 addition & 2 deletions agent/agentssh/signal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (

func osSignalFrom(sig ssh.Signal) os.Signal {
switch sig {
case ssh.SIGINT:
return os.Interrupt
// Signals are not supported on Windows.
default:
return os.Kill
}
Expand Down