summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtyom V. Poptsov <poptsov.artyom@gmail.com>2015-02-12 07:10:24 +0300
committerArtyom V. Poptsov <poptsov.artyom@gmail.com>2015-02-12 07:10:24 +0300
commitdd69590e51cb7e9210658cc108ffe865d8c93cbc (patch)
tree46423347a6b59b7aebd5861aec4567b868f15c10
parentchannel-func.c (guile_ssh_channel_request_send_exit_status): Update docstring (diff)
downloadguile-ssh-dd69590e51cb7e9210658cc108ffe865d8c93cbc.tar.gz
examples/sssh{,d}.scm.in: Handle exit status
* examples/ssshd.scm.in (handle-request-exec): Send exit status. * examples/sssh.scm.in (main): Handle exit status. * NEWS: Update.
-rw-r--r--ChangeLog6
-rw-r--r--NEWS6
-rw-r--r--examples/sssh.scm.in23
-rw-r--r--examples/ssshd.scm.in5
4 files changed, 32 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d77531..2f7b591 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-12 Artyom Poptsov <poptsov.artyom@gmail.com>
+
+ * examples/ssshd.scm.in (handle-request-exec): Send exit status.
+ * examples/sssh.scm.in (main): Handle exit status.
+ * NEWS: Update.
+
2015-02-09 Artyom Poptsov <poptsov.artyom@gmail.com>
* doc/api-channels.texi (Channels): Update description of
diff --git a/NEWS b/NEWS
index a9006f3..30493ca 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,12 @@ Copyright (C) Artyom V. Poptsov <poptsov.artyom@gmail.com>
** New `channel-request-send-exit-status' procedure in (ssh channel)
The procedure can be used to send the exit status to a client.
** Improve printing of Guile-SSH server objects
+** Update examples
+*** sssh
+ - Check exit status of an executed command.
+*** ssshd
+ - Send exit status to the client according to the result of command
+ execution.
** Update documentation
- Add description of the new procedures.
diff --git a/examples/sssh.scm.in b/examples/sssh.scm.in
index 6894a70..bb1f79e 100644
--- a/examples/sssh.scm.in
+++ b/examples/sssh.scm.in
@@ -209,14 +209,21 @@ Options:
(print-debug "8. channel-request-exec (ssh_channel_request_exec)\n")
(channel-request-exec channel cmd)
- (print-debug "9. channel-poll (ssh_channel_poll)\n")
- (let poll ((ready? #f))
- (if ready?
- (begin
- (print-debug "10. channel-read (ssh_channel_read)\n")
- (display (read-all channel))
- (newline))
- (poll (char-ready? channel))))
+ (case (channel-get-exit-status channel)
+ ((0)
+ (print-debug "9. channel-poll (ssh_channel_poll)\n")
+ (let poll ((ready? #f))
+ (if ready?
+ (begin
+ (print-debug "10. channel-read (ssh_channel_read)\n")
+ (display (read-all channel))
+ (newline))
+ (poll (char-ready? channel)))))
+ (else =>
+ (lambda (status)
+ (format #t
+ "ERROR: Failed to execute command `~a' (exit status ~a)~%"
+ cmd status))))
(close channel)
(disconnect! session))))))
diff --git a/examples/ssshd.scm.in b/examples/ssshd.scm.in
index 0c595d7..ba52818 100644
--- a/examples/ssshd.scm.in
+++ b/examples/ssshd.scm.in
@@ -82,6 +82,11 @@
(format #t " cmd: ~a~%" cmd)
(let* ((port (open-input-pipe cmd))
(res (read-all port)))
+
+ (if (string-null? res)
+ (channel-request-send-exit-status channel 1)
+ (channel-request-send-exit-status channel 0))
+
(display res channel))))
(define (handle-req-auth session msg msg-type)