summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/guestfs-actions.c82
-rw-r--r--src/guestfs-actions.h1
-rw-r--r--src/guestfs_protocol.h3
-rw-r--r--src/guestfs_protocol.x1
4 files changed, 86 insertions, 1 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;
+}
+
diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h
index b14840c9..f2218f4e 100644
--- a/src/guestfs-actions.h
+++ b/src/guestfs-actions.h
@@ -131,3 +131,4 @@ 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);
+extern int guestfs_ping_daemon (guestfs_h *handle);
diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h
index 40c84eea..e4725247 100644
--- a/src/guestfs_protocol.h
+++ b/src/guestfs_protocol.h
@@ -881,7 +881,8 @@ enum guestfs_procedure {
GUESTFS_PROC_MV = 89,
GUESTFS_PROC_DROP_CACHES = 90,
GUESTFS_PROC_DMESG = 91,
- GUESTFS_PROC_NR_PROCS = 91 + 1,
+ GUESTFS_PROC_PING_DAEMON = 92,
+ GUESTFS_PROC_NR_PROCS = 92 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x
index 4bf42be9..e61d3fb8 100644
--- a/src/guestfs_protocol.x
+++ b/src/guestfs_protocol.x
@@ -706,6 +706,7 @@ enum guestfs_procedure {
GUESTFS_PROC_MV = 89,
GUESTFS_PROC_DROP_CACHES = 90,
GUESTFS_PROC_DMESG = 91,
+ GUESTFS_PROC_PING_DAEMON = 92,
GUESTFS_PROC_NR_PROCS
};