diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-05-01 11:47:31 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-05-01 11:47:31 +0100 |
commit | 8c3b820c2b687345448e3d74a7101b07ff32688e (patch) | |
tree | 0cf5be9515ddcaa1ef6e74c2c55fca5760400c1c /src/guestfs-actions.c | |
parent | 632012e6419f04fab93909f92ecbab5a2c590447 (diff) | |
download | libguestfs-8c3b820c2b687345448e3d74a7101b07ff32688e.tar.gz libguestfs-8c3b820c2b687345448e3d74a7101b07ff32688e.tar.xz libguestfs-8c3b820c2b687345448e3d74a7101b07ff32688e.zip |
Generated code for ping-daemon command.
Diffstat (limited to 'src/guestfs-actions.c')
-rw-r--r-- | src/guestfs-actions.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 94963ff0..c0762dfa 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -8253,3 +8253,85 @@ char *guestfs_dmesg (guestfs_h *g) return ctx.ret.kmsgs; /* caller will free */ } +struct ping_daemon_ctx { + /* This flag is set by the callbacks, so we know we've done + * the callbacks as expected, and in the right sequence. + * 0 = not called, 1 = reply_cb called. + */ + int cb_sequence; + struct guestfs_message_header hdr; + struct guestfs_message_error err; +}; + +static void ping_daemon_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct ping_daemon_ctx *ctx = (struct ping_daemon_ctx *) data; + + /* This should definitely not happen. */ + if (ctx->cb_sequence != 0) { + ctx->cb_sequence = 9999; + error (g, "%s: internal error: reply callback called twice", "guestfs_ping_daemon"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_ping_daemon"); + return; + } + if (ctx->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &ctx->err)) { + error (g, "%s: failed to parse reply error", "guestfs_ping_daemon"); + return; + } + goto done; + } + done: + ctx->cb_sequence = 1; +} + +int guestfs_ping_daemon (guestfs_h *g) +{ + struct ping_daemon_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_ping_daemon") == -1) return -1; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + serial = guestfs__send_sync (g, GUESTFS_PROC_PING_DAEMON, NULL, NULL); + if (serial == -1) { + guestfs_set_ready (g); + return -1; + } + + guestfs__switch_to_receiving (g); + ctx.cb_sequence = 0; + guestfs_set_reply_callback (g, ping_daemon_reply_cb, &ctx); + (void) ml->main_loop_run (ml, g); + guestfs_set_reply_callback (g, NULL, NULL); + if (ctx.cb_sequence != 1) { + error (g, "%s reply failed, see earlier error messages", "guestfs_ping_daemon"); + guestfs_set_ready (g); + return -1; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PING_DAEMON, serial) == -1) { + guestfs_set_ready (g); + return -1; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return -1; + } + + guestfs_set_ready (g); + return 0; +} + |