From: Richard W.M. Jones Date: Fri, 26 Aug 2011 19:28:20 +0000 (+0100) Subject: Add GUESTFS_EVENT_ENTER event. X-Git-Tag: 1.13.9~5 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=9420eaf44ec4067c3740b91b0be0fede08a0c515;p=libguestfs.git Add GUESTFS_EVENT_ENTER event. This event is generated whenever a libguestfs function is called. --- diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 5460a35..bfdea33 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -758,6 +758,13 @@ trace_send_line (guestfs_h *g) "; + (* Generate code for enter events. *) + let enter_event shortname = + pr " guestfs___call_callbacks_message (g, GUESTFS_EVENT_ENTER,\n"; + pr " \"%s\", %d);\n" + shortname (String.length shortname) + in + (* Generate code to check String-like parameters are not passed in * as NULL (returning an error if they are). *) @@ -1027,6 +1034,7 @@ trace_send_line (guestfs_h *g) pr " struct guestfs_%s_list *r;\n" typ ); pr "\n"; + enter_event shortname; check_null_strings shortname style; reject_unknown_optargs shortname style; trace_call shortname style; @@ -1119,6 +1127,7 @@ trace_send_line (guestfs_h *g) pr " const uint64_t progress_hint = 0;\n"; pr "\n"; + enter_event shortname; check_null_strings shortname style; reject_unknown_optargs shortname style; trace_call shortname style; diff --git a/generator/generator_events.ml b/generator/generator_events.ml index 54557c3..df74af3 100644 --- a/generator/generator_events.ml +++ b/generator/generator_events.ml @@ -35,6 +35,8 @@ let events = [ qemu / kernel / guestfsd / tools *) "library"; (* log messages from library *) "trace"; (* call trace messages *) + + "enter"; (* enter a function *) ] let events = mapi (fun i name -> name, 1 lsl i) events diff --git a/src/events.c b/src/events.c index aa30fd2..f707e0b 100644 --- a/src/events.c +++ b/src/events.c @@ -111,12 +111,14 @@ guestfs___call_callbacks_message (guestfs_h *g, uint64_t event, count++; } - /* If nothing was registered and we're verbose or tracing, then we - * print the message on stderr. This essentially emulates the - * behaviour of the old-style handlers, while allowing callers to - * override print-on-stderr simply by registering a callback. + /* Emulate the old-style handlers. Callers can override + * print-on-stderr simply by registering a callback. */ - if (count == 0 && (g->verbose || event == GUESTFS_EVENT_TRACE)) { + if (count == 0 && + (event == GUESTFS_EVENT_APPLIANCE || + event == GUESTFS_EVENT_LIBRARY || + event == GUESTFS_EVENT_TRACE) && + (g->verbose || event == GUESTFS_EVENT_TRACE)) { int from_appliance = event == GUESTFS_EVENT_APPLIANCE; size_t i; char c; diff --git a/src/guestfs.pod b/src/guestfs.pod index 8cb1b86..6cceced 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -1833,6 +1833,21 @@ If no callback is registered: the messages are sent to stderr. You can override the printing of trace messages to stderr by setting up a callback. +=item GUESTFS_EVENT_ENTER +(payload type: function name) + +The callback function is called whenever a libguestfs function +is entered. + +The payload is a string which contains the name of the function +that we are entering (not including C prefix). + +Note that libguestfs functions can call themselves, so you may +see many events from a single call. A few libguestfs functions +do not generate this event. + +If no callback is registered: the event is ignored. + =back =head3 guestfs_set_event_callback