func (sess *session) handleSignalRequest(request *ssh.Request) {
	logger := sess.logger.Session("handle-signal-request")

	type signalMsg struct {
		Signal string
	}
	var signalMessage signalMsg

	err := ssh.Unmarshal(request.Payload, &signalMessage)
	if err != nil {
		logger.Error("unmarshal-failed", err)
		if request.WantReply {
			request.Reply(false, nil)
		}
		return
	}

	sess.Lock()
	defer sess.Unlock()

	cmd := sess.command

	if cmd != nil {
		signal := signals.SyscallSignals[ssh.Signal(signalMessage.Signal)]
		err := sess.runner.Signal(cmd, signal)
		if err != nil {
			logger.Error("process-signal-failed", err)
		}
	}

	if request.WantReply {
		request.Reply(true, nil)
	}
}
Пример #2
0
func (s *SignalMsg) FromString(name string) error {
	num, err := strconv.Atoi(name)
	if err == nil {
		for sig, val := range Signals {
			if num == val {
				s.Signal = sig
				return nil
			}
		}
	}

	name = strings.TrimPrefix(strings.ToUpper(name), "SIG")

	s.Signal = ssh.Signal(name)
	_, ok := Signals[s.Signal]
	if !ok {
		return fmt.Errorf("unsupported signal name: %q", name)
	}

	return nil
}