From f2438b75a2402af0c51f89d4cd993a4ab7ef4a8c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 24 Jun 2015 12:43:32 +0100 Subject: [PATCH] tests: daemon: Cleanly shut down the daemon on exit. This refines the previous commit by shutting down the daemon cleanly at the end of the test (assuming the test was successful). It repurposes the 'internal_exit' API for this, which was previously used by the now defunct --enable-valgrind-daemon functionality. --- daemon/internal.c | 7 +------ generator/actions.ml | 3 ++- tests/daemon/captive-daemon.pm.in | 12 +++++------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/daemon/internal.c b/daemon/internal.c index 781366d69..5fb3d54c3 100644 --- a/daemon/internal.c +++ b/daemon/internal.c @@ -46,14 +46,9 @@ do_internal_autosync (void) } /* NB: Only called when valgrinding the daemon. */ -int +int __attribute__((noreturn)) do_internal_exit (void) { - if (!autosync_umount) { - reply_with_error ("guestfsd -r flag used, ignoring"); - return -1; - } - /* Send a reply before exiting so the protocol doesn't get confused. */ reply (NULL, NULL); diff --git a/generator/actions.ml b/generator/actions.ml index 6089afa44..372e50e0e 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -11951,7 +11951,8 @@ This function is used internally when setting up the appliance." }; name = "internal_exit"; added = (1, 23, 30); style = RErr, [], []; proc_nr = Some 414; - visibility = VInternal; + (* Really VInternal, but we need to use it from the Perl bindings. XXX *) + visibility = VDebug; cancellable = true; shortdesc = "cause the daemon to exit (internal use only)"; longdesc = "\ diff --git a/tests/daemon/captive-daemon.pm.in b/tests/daemon/captive-daemon.pm.in index 991a9a1eb..19833b862 100644 --- a/tests/daemon/captive-daemon.pm.in +++ b/tests/daemon/captive-daemon.pm.in @@ -93,14 +93,15 @@ sub run_tests { # libguestfs live. $g = Sys::Guestfs->new (); $g->set_backend ("unix:" . $sockname); + $g->set_autosync (0); $g->launch; # Run the user tests. my $r = ::tests ($g); - # Close the socket. The daemon should now exit. - $g->shutdown (); - $g->close (); + # Tell the daemon to exit cleanly, and remove the socket. + $g->internal_exit; + $g->close; unlink $sockname; waitpid ($pid, 0) or die "waitpid: $!"; @@ -112,10 +113,7 @@ sub run_tests { my $status = $? >> 8; die "ERROR: guestfsd died with exit code 119 (valgrind failure)\n" if $status == 119; - - # Note we allow guestfsd to die with exit code 1, because - # that indicates a read failure from the socket. - die "ERROR: guestfsd died with exit code $status\n" if $status > 1; + die "ERROR: guestfsd died with exit code $status\n"; } # Exit with failure if the user test failed.