diff options
-rw-r--r-- | fish/fish.c | 7 | ||||
-rw-r--r-- | fish/rc.c | 9 | ||||
-rwxr-xr-x | fish/test-remote-events.sh | 42 |
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); @@ -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 |