[Libguestfs] [PATCH 1/2] fish: Allow events to be processed in guestfish.

Richard W.M. Jones rjones at redhat.com
Wed Dec 14 08:44:40 UTC 2011


From: "Richard W.M. Jones" <rjones at redhat.com>

Add 'event' and 'delete-event' commands so that event handlers
can be registered and deleted in guestfish.  The event handler
is a shell script snippet or host command.

Cc: Pádraig Brady <P at draigBrady.com>
---
 generator/generator_actions.ml |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index dae837b..7d7c7af 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -6675,6 +6675,16 @@ them with the help of L</glob> like this:
 
  glob copy-out /home/* .");
 
+  ("delete_event", (RErr,[], []), -1, [], [],
+   "delete a previously registered event handler",
+   " delete-event name
+
+Delete the event handler which was previously registered as C<name>.
+If multiple event handlers were registered with the same name, they
+are all deleted.
+
+See also the guestfish C<event> command.");
+
   ("display", (RErr,[], []), -1, [], [],
    "display an image",
    " display filename
@@ -6706,6 +6716,35 @@ The editor is C<$EDITOR>.  However if you use the alternate
 commands C<vi> or C<emacs> you will get those corresponding
 editors.");
 
+  ("event", (RErr,[], []), -1, [], [],
+   "register a handler for an event or events",
+   " event name eventset \"shell script ...\"
+
+Register a shell script fragment which is executed when an
+event is raised.  See L<guestfs(3)/guestfs_set_event_callback>
+for a discussion of the event API in libguestfs.
+
+The C<name> parameter is a name that you give to this event
+handler.  It can be any string (even the empty string) and is
+simply there so you can delete the handler using the guestfish
+C<delete-event> command.
+
+The C<eventset> parameter is a comma-separated list of one
+or more events.
+
+The third and final parameter is the shell script fragment
+(or any external command) that is executed when any of the
+events in the eventset occurs.  It is executed using
+C<$SHELL -c>, or if C<$SHELL> is not set then C</bin/sh -c>.
+
+The shell script fragment receives callback parameters as
+arguments C<$1>, C<$2> etc.  The actual event that was
+called is available in the environment variable C<$EVENT>.
+
+ event \"\" close \"echo closed\"
+ event messages appliance,library,trace \"echo $*\"
+ event \"\" progress \"echo progress: $3/$4\"");
+
   ("glob", (RErr,[], []), -1, [], [],
    "expand wildcards in command",
    " glob command args...
-- 
1.7.6




More information about the Libguestfs mailing list