diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-05-01 11:27:52 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-05-01 11:27:52 +0100 |
commit | 24bee20ce4196d45891925332a47a05aa5e40938 (patch) | |
tree | 434b56343dde38ae0c877cab236ada753e2f8549 /src/guestfs-actions.c | |
parent | 8c60f5c681b5d7cf90bc798fcaf94cd4e242e27f (diff) | |
download | libguestfs-24bee20ce4196d45891925332a47a05aa5e40938.tar.gz libguestfs-24bee20ce4196d45891925332a47a05aa5e40938.tar.xz libguestfs-24bee20ce4196d45891925332a47a05aa5e40938.zip |
Generated code for dmesg command.
Diffstat (limited to 'src/guestfs-actions.c')
-rw-r--r-- | src/guestfs-actions.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 99f8a446..94963ff0 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -8166,3 +8166,90 @@ int guestfs_drop_caches (guestfs_h *g, return 0; } +struct dmesg_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; + struct guestfs_dmesg_ret ret; +}; + +static void dmesg_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct dmesg_ctx *ctx = (struct dmesg_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_dmesg"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_dmesg"); + 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_dmesg"); + return; + } + goto done; + } + if (!xdr_guestfs_dmesg_ret (xdr, &ctx->ret)) { + error (g, "%s: failed to parse reply", "guestfs_dmesg"); + return; + } + done: + ctx->cb_sequence = 1; +} + +char *guestfs_dmesg (guestfs_h *g) +{ + struct dmesg_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_dmesg") == -1) return NULL; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + serial = guestfs__send_sync (g, GUESTFS_PROC_DMESG, NULL, NULL); + if (serial == -1) { + guestfs_set_ready (g); + return NULL; + } + + guestfs__switch_to_receiving (g); + ctx.cb_sequence = 0; + guestfs_set_reply_callback (g, dmesg_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_dmesg"); + guestfs_set_ready (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DMESG, serial) == -1) { + guestfs_set_ready (g); + return NULL; + } + + if (ctx.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", ctx.err.error_message); + guestfs_set_ready (g); + return NULL; + } + + guestfs_set_ready (g); + return ctx.ret.kmsgs; /* caller will free */ +} + |