Skip to content

Commit

Permalink
Bind ssh_channel_request_send_signal
Browse files Browse the repository at this point in the history
  • Loading branch information
fmang authored and fwininger committed Sep 15, 2023
1 parent 73abba8 commit 97dd079
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ext/libssh_ruby/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ static VALUE m_request_pty(VALUE self) {
return Qnil;
}

/*
* @overload request_send_signal
* Send a signal to the remote process.
* @param [String] signal The signal to send without the SIG prefix (e.g. 'HUP').
* @return [nil]
* @see http://api.libssh.org/stable/group__libssh__channel.html
* ssh_channel_request_send_signal
*/
static VALUE m_request_send_signal(VALUE self, VALUE signal) {
ChannelHolder *holder;
TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder);
int rc = ssh_channel_request_send_signal(holder->channel, StringValueCStr(signal));
RAISE_IF_ERROR(rc);
return Qnil;
}

struct nogvl_read_args {
ssh_channel channel;
char *buf;
Expand Down Expand Up @@ -640,6 +656,8 @@ void Init_libssh_channel(void) {
RUBY_METHOD_FUNC(m_request_exec), 1);
rb_define_method(rb_cLibSSHChannel, "request_pty",
RUBY_METHOD_FUNC(m_request_pty), 0);
rb_define_method(rb_cLibSSHChannel, "request_send_signal",
RUBY_METHOD_FUNC(m_request_send_signal), 1);
rb_define_method(rb_cLibSSHChannel, "read", RUBY_METHOD_FUNC(m_read), -1);
rb_define_method(rb_cLibSSHChannel, "read_nonblocking",
RUBY_METHOD_FUNC(m_read_nonblocking), -1);
Expand Down
18 changes: 18 additions & 0 deletions spec/integration/channel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@
end
end

describe '#request_send_signal' do
before do
session.connect
session.userauth_publickey_auto
end

it 'sends a signal to the remote process' do
before = Time.now
channel.open_session do
channel.request_exec('sleep 2')
channel.request_send_signal('HUP')
LibSSH::Channel.select([channel], [], [], 1) until channel.eof?
end
after = Time.now
expect(after - before).to be < 1
end
end

describe '#read_nonblocking' do
before do
session.connect
Expand Down

0 comments on commit 97dd079

Please sign in to comment.