Skip to content

Add send_signal method to Channel - #1535

Open
MrMino wants to merge 2 commits into
paramiko:mainfrom
MrMino:channel_send_signal
Open

MrMino wants to merge 2 commits into
paramiko:mainfrom
MrMino:channel_send_signal

Conversation

@MrMino

@MrMino MrMino commented Oct 29, 2019

Copy link
Copy Markdown
Contributor

Implemented as per section 6.9 of RFC 4254 ("The Secure Shell (SSH)
Connection Protocol"). Support for this request was added in OpenSSH
7.9. Support in other implementations may vary.

@MrMino

MrMino commented Mar 20, 2020

Copy link
Copy Markdown
Contributor Author

@bitprophet any update on this? As people are moving away from older OpenSSH versions now, it would be a very nice-to-have. The PR is relatively simple.

@MrMino

MrMino commented Feb 27, 2021

Copy link
Copy Markdown
Contributor Author

Note to self: should this ever be pursued further, exit code fetching would also have to be improved, see #823

@greezybacon

greezybacon commented Mar 10, 2021 •

Copy link
Copy Markdown

Any reason on why this cannot be merged? I ended up implementing this myself. And, when I looked through the pull requests prior to creating my own, I found this one. Great work, @MrMino.

The only thing I can think to add would be a translation between the Python signal library and the text signal name to send:

import signal

class Channel(...):
   ...

    def send_signal(self, name):
        if type(name) is signal.Signals:
            name = signal.name[3:]
        if type(name) is not str:
            raise ValueError('%s: Unsupported signal name/type' % (name,))

@bskinn

bskinn commented Mar 12, 2021

Copy link
Copy Markdown
Contributor

This PR only includes the code change; if augmented with docs and tests, that would facilitate a potential merge.

@MrMino

MrMino commented Mar 12, 2021 •

Copy link
Copy Markdown
Contributor Author

@baskinn I thought the docs are generated via autodoc? I'll add some tests today / tomorrow.

Edit: looks like they are automated in the reference section, but I'll make sure to test it out too, and in case it doesn't show up - add it too.

@greezybacon

Copy link
Copy Markdown

@MrMino I would be happy to help in any capacity. Please advise/delegate if you'd like a teammate on this.

@bskinn

bskinn commented Mar 12, 2021

Copy link
Copy Markdown
Contributor

@MrMino Oh, right, yeah -- the docstring should do it. Sorry!

@bitprophet bitprophet added this to the p1 milestone Mar 19, 2021
@rustyscottweber

Copy link
Copy Markdown

@bitprophet: Is there a process to get this merged? I've double checked that this commit can be re-based on top of the main branch. What do you need me to do to get this merged?

@bitprophet

Copy link
Copy Markdown
Member

@rustyscottweber Just needs me to get through the milestones until I reach the one this is in, sadly. However after glancing at the diff this is pretty darn straightforward so I'll bump it to an earlier one.

@travisdowns

Copy link
Copy Markdown

I still have my fingers crossed this will be merged one day!

@bskinn

bskinn commented Jul 5, 2023

Copy link
Copy Markdown
Contributor

Coming back to this after the mention in #1475.

Is this something that could easily have tests added?

Also, this would need an entry in /sites/www/changelog.rst.

@MrMino

MrMino commented Sep 18, 2024 •

Copy link
Copy Markdown
Contributor Author

@bskinn @bitprophet I'd like to revive this.

If anyone can point me to an existing example of how the tests for low-level protocol code like this should look like, I'd be happy to add them.
Other Channel methods such as resize_pty(), invoke_subsystem(), or get_pty() doesn't seem to be tested on this level either, and I'm afraid the required test infrastructure might not exist in the repo. My only idea for testing this is to check whether the channel sends the right bytes (i.e. some double-bookkeeping that ensures that the Right Thing™ isn't changed to the Wrong Thing™ by mistake).

If you are thinking about an end-to-end tests with a stub Paramiko SSH server, the server-side code would need to be implemented first, which I believe is a bit higher toll.

@MrMino
MrMino force-pushed the channel_send_signal branch from 047ccf4 to 9d709b6 Compare September 18, 2024 18:59
@MrMino

MrMino commented Sep 18, 2024 •

Copy link
Copy Markdown
Contributor Author

@greezybacon Integrating the signal module into this would be a mistake.

The signals exposed in stdlib are platform dependent. By supporting these enums here, we would be inadvertently inviting misuse by code that only works when the platforms of the server and the client match.

@MrMino

MrMino commented Oct 24, 2024

Copy link
Copy Markdown
Contributor Author

This code is now happily running in a larger environment. I also tested it myself on one of OpenSSH versions from 2023.

@bskinn

bskinn commented Oct 27, 2024 •

Copy link
Copy Markdown
Contributor

@MrMino, I'll bump this up to bitprophet again; he may think that specific tests aren't needed here, in which case I would think this is close to merge-able.

Please add an initial draft of an entry to sites/www/changelog.rst now, I don't think that should need bitprophet's input.

Also, please expand the docstring of the new function -- at minimum, replicate (with suitable edits if appropriate) the comment in the up-top PR description, including the link to the RFC.

Additionally, if there are any context-specific reasons for the specific calls to the .add_ methods of m, it would be good to add comments explaining those also. (E.g., is each value added to the message for the purposes of satisfying paramiko's machinery, or for meeting the RFC spec, or for both?)

Thanks!

@MrMino
MrMino force-pushed the channel_send_signal branch from 9d709b6 to c2f0964 Compare November 1, 2024 20:01
@MrMino

MrMino commented Nov 1, 2024

Copy link
Copy Markdown
Contributor Author

@bskinn done.

Additionally, if there are any context-specific reasons for the specific calls to the .add_ methods of m, it would be good to add comments explaining those also.

There are none. It is taken straight from the RFC.

@MrMino
MrMino force-pushed the channel_send_signal branch from c2f0964 to 2ef0807 Compare November 4, 2024 08:39
@MrMino

MrMino commented Nov 4, 2024

Copy link
Copy Markdown
Contributor Author

(force pushed again to fix a linter warning)

@MrMino

MrMino commented Nov 8, 2024

Copy link
Copy Markdown
Contributor Author

@bskinn Do you see anything else to add here? Can we get the "Needs *" labels detached from this PR?

@bskinn

bskinn commented Nov 22, 2024

Copy link
Copy Markdown
Contributor

Sorry for the delay, @MrMino -- yes, I think CHANGELOG/docs are good now, I've pulled that label.

I'm going to leave the 'needs tests' on for now as a reminder. bitprophet has continued to be tight on OSS time lately, but I've got this PR on the list for him to consider the next time he has opportunity.

MrMino added 2 commits June 5, 2025 07:45
Implemented as per section 6.9 of RFC 4254 ("The Secure Shell (SSH)
Connection Protocol"). Support for this request was added in OpenSSH
7.9. Support in other implementations may vary.
@MrMino
MrMino force-pushed the channel_send_signal branch from 2ef0807 to a26f1ac Compare June 5, 2025 05:46
@MrMino

MrMino commented Jun 10, 2025

Copy link
Copy Markdown
Contributor Author

FTR test failures are unrelated, happened after a rebase.

The following MR adds handlers for exit-signal messages that come from the server if the process was killed by a signal: #2517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants