diff options
author | Dmitry V. Krivenok <krivenok@orangesystem.ru> | 2009-09-10 13:34:40 +0400 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-09-10 12:34:58 +0200 |
commit | df4c62212cc34dd19714751d1eada22fdccfa6da (patch) | |
tree | 13192d479437e3f4da70e18210446cd8816b52b4 /libssh/channels.c | |
parent | 97b6036cbf3e444384a8e9b7f082e22d9ea64fe1 (diff) | |
download | libssh-df4c62212cc34dd19714751d1eada22fdccfa6da.tar.gz libssh-df4c62212cc34dd19714751d1eada22fdccfa6da.tar.xz libssh-df4c62212cc34dd19714751d1eada22fdccfa6da.zip |
Support for sending signals (RFC 4254, section 6.9).
Added function
int channel_request_send_signal(ssh_channel channel, const char *signal);
which implements signals delivery (as described in RFC 4254).
Only SSH-v2 is currently supported.
Signed-off-by: Dmitry V. Krivenok <krivenok@orangesystem.ru>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
Diffstat (limited to 'libssh/channels.c')
-rw-r--r-- | libssh/channels.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libssh/channels.c b/libssh/channels.c index 6e70285c..ed405892 100644 --- a/libssh/channels.c +++ b/libssh/channels.c @@ -1654,6 +1654,57 @@ error: return rc; } + +/** + * @brief Send a signal to remote process (as described in RFC 4254, section 6.9). + * + * Sends a signal 'signal' to the remote process. + * Note, that remote system may not support signals concept. + * In such a case this request will be silently ignored. + * Only SSH-v2 is supported (I'm not sure about SSH-v1). + * + * @param channel The channel to send signal. + * + * @param signal The signal to send (without SIG prefix) + * (e.g. "TERM" or "KILL"). + * + * @return SSH_SUCCESS on success, SSH_ERROR on error (including attempt to send signal via SSH-v1 session). + * + */ +int channel_request_send_signal(ssh_channel channel, const char *signal) { + ssh_buffer buffer = NULL; + ssh_string encoded_signal = NULL; + int rc = SSH_ERROR; + +#ifdef WITH_SSH1 + if (channel->version == 1) { + return SSH_ERROR; // TODO: Add support for SSH-v1 if possible. + } +#endif + + buffer = buffer_new(); + if (buffer == NULL) { + goto error; + } + + encoded_signal = string_from_char(signal); + if (encoded_signal == NULL) { + goto error; + } + + if (buffer_add_ssh_string(buffer, encoded_signal) < 0) { + goto error; + } + + rc = channel_request(channel, "signal", buffer, 0); +error: + buffer_free(buffer); + string_free(encoded_signal); + return rc; +} + + + /* TODO : fix the delayed close thing */ /* TODO : fix the blocking behaviours */ |