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 | |
parent | 8c60f5c681b5d7cf90bc798fcaf94cd4e242e27f (diff) | |
download | libguestfs-24bee20ce4196d45891925332a47a05aa5e40938.tar.gz libguestfs-24bee20ce4196d45891925332a47a05aa5e40938.tar.xz libguestfs-24bee20ce4196d45891925332a47a05aa5e40938.zip |
Generated code for dmesg command.
Diffstat (limited to 'src')
-rw-r--r-- | src/guestfs-actions.c | 87 | ||||
-rw-r--r-- | src/guestfs-actions.h | 1 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 10 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 10 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 5 |
5 files changed, 112 insertions, 1 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 */ +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index ef4e775c..b14840c9 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -130,3 +130,4 @@ extern int guestfs_cp (guestfs_h *handle, const char *src, const char *dest); extern int guestfs_cp_a (guestfs_h *handle, const char *src, const char *dest); extern int guestfs_mv (guestfs_h *handle, const char *src, const char *dest); extern int guestfs_drop_caches (guestfs_h *handle, int whattodrop); +extern char *guestfs_dmesg (guestfs_h *handle); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 395e710f..7a40e14e 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -1518,6 +1518,16 @@ xdr_guestfs_drop_caches_args (XDR *xdrs, guestfs_drop_caches_args *objp) } bool_t +xdr_guestfs_dmesg_ret (XDR *xdrs, guestfs_dmesg_ret *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->kmsgs, ~0)) + return FALSE; + return TRUE; +} + +bool_t xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp) { register int32_t *buf; diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h index a3bf1855..40c84eea 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -784,6 +784,11 @@ struct guestfs_drop_caches_args { }; typedef struct guestfs_drop_caches_args guestfs_drop_caches_args; +struct guestfs_dmesg_ret { + char *kmsgs; +}; +typedef struct guestfs_dmesg_ret guestfs_dmesg_ret; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -875,7 +880,8 @@ enum guestfs_procedure { GUESTFS_PROC_CP_A = 88, GUESTFS_PROC_MV = 89, GUESTFS_PROC_DROP_CACHES = 90, - GUESTFS_PROC_NR_PROCS = 90 + 1, + GUESTFS_PROC_DMESG = 91, + GUESTFS_PROC_NR_PROCS = 91 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1048,6 +1054,7 @@ extern bool_t xdr_guestfs_cp_args (XDR *, guestfs_cp_args*); extern bool_t xdr_guestfs_cp_a_args (XDR *, guestfs_cp_a_args*); extern bool_t xdr_guestfs_mv_args (XDR *, guestfs_mv_args*); extern bool_t xdr_guestfs_drop_caches_args (XDR *, guestfs_drop_caches_args*); +extern bool_t xdr_guestfs_dmesg_ret (XDR *, guestfs_dmesg_ret*); extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*); extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*); extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*); @@ -1179,6 +1186,7 @@ extern bool_t xdr_guestfs_cp_args (); extern bool_t xdr_guestfs_cp_a_args (); extern bool_t xdr_guestfs_mv_args (); extern bool_t xdr_guestfs_drop_caches_args (); +extern bool_t xdr_guestfs_dmesg_ret (); extern bool_t xdr_guestfs_procedure (); extern bool_t xdr_guestfs_message_direction (); extern bool_t xdr_guestfs_message_status (); diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x index 68b0ac4d..4bf42be9 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -610,6 +610,10 @@ struct guestfs_drop_caches_args { int whattodrop; }; +struct guestfs_dmesg_ret { + string kmsgs<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -701,6 +705,7 @@ enum guestfs_procedure { GUESTFS_PROC_CP_A = 88, GUESTFS_PROC_MV = 89, GUESTFS_PROC_DROP_CACHES = 90, + GUESTFS_PROC_DMESG = 91, GUESTFS_PROC_NR_PROCS }; |