summaryrefslogtreecommitdiffstats
path: root/fish
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-03-12 15:14:54 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-03-12 15:21:35 +0000
commit17182af3a6de8e3e94e0a914416c54f09bb74007 (patch)
tree56fe3b0684849f169eb6405956f6e3c1a05d829b /fish
parentf7c744bbf819b5984cbd3569d35d82a0451996b3 (diff)
downloadlibguestfs-17182af3a6de8e3e94e0a914416c54f09bb74007.tar.gz
libguestfs-17182af3a6de8e3e94e0a914416c54f09bb74007.tar.xz
libguestfs-17182af3a6de8e3e94e0a914416c54f09bb74007.zip
fish: remote: Output from close event now passed over stdout (RHBZ#802389).
Diffstat (limited to 'fish')
-rw-r--r--fish/fish.c7
-rw-r--r--fish/rc.c9
-rwxr-xr-xfish/test-remote-events.sh42
3 files changed, 55 insertions, 3 deletions
diff --git a/fish/fish.c b/fish/fish.c
index ac16df5d..8e3e9fb2 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -495,7 +495,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE);
}
rc_listen ();
- goto out;
+ goto out_after_handle_close;
}
/* -f (file) parameter? */
@@ -546,13 +546,14 @@ main (int argc, char *argv[])
else
cmdline (argv, optind, argc);
- out:
+ guestfs_close (g);
+
+ out_after_handle_close:
cleanup_readline ();
if (progress_bars)
progress_bar_free (bar);
- guestfs_close (g);
free_event_handlers ();
exit (EXIT_SUCCESS);
diff --git a/fish/rc.c b/fish/rc.c
index aa12820a..4c119f7b 100644
--- a/fish/rc.c
+++ b/fish/rc.c
@@ -291,6 +291,15 @@ rc_listen (void)
xdr_free ((xdrproc_t) xdr_guestfish_call, (char *) &call);
+ /* RHBZ#802389: If the command is quit, close the handle right
+ * away. Note that the main while loop will exit preventing
+ * 'g' from being reused.
+ */
+ if (quit) {
+ guestfs_close (g);
+ g = NULL;
+ }
+
/* Send the reply. */
xdrstdio_create (&xdr2, fp, XDR_ENCODE);
(void) xdr_guestfish_reply (&xdr2, &reply);
diff --git a/fish/test-remote-events.sh b/fish/test-remote-events.sh
new file mode 100755
index 00000000..bf96db69
--- /dev/null
+++ b/fish/test-remote-events.sh
@@ -0,0 +1,42 @@
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2012 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Test remote events in guestfish.
+
+set -e
+
+eval "$(./guestfish --listen)"
+
+./guestfish --remote event close_event close "echo closed"
+
+output="$(./guestfish --remote list-events)"
+if [ "$output" != '"close_event": (0): close: echo closed' ]; then
+ echo "$0: list-events failed:"
+ echo "$output"
+ ./guestfish --remote exit
+ exit 1
+fi
+
+# Test close event (RHBZ#802389).
+output="$(./guestfish --remote quit)"
+
+if [ "$output" != '"closed"']; then
+ echo "$0: close event failed:"
+ echo "$output"
+ exit 1
+fi