summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-03 19:08:19 +0100
committerRichard Jones <rjones@redhat.com>2009-04-03 19:08:19 +0100
commitd134143b55ecb5f7e6f74318acbf04f9e1370af6 (patch)
treedd12c32499204fc9967babb5b3207143e644e631 /src
parent40ca9a57829f2e82362e391d7d998bf33c8bd671 (diff)
downloadlibguestfs-d134143b55ecb5f7e6f74318acbf04f9e1370af6.tar.gz
libguestfs-d134143b55ecb5f7e6f74318acbf04f9e1370af6.tar.xz
libguestfs-d134143b55ecb5f7e6f74318acbf04f9e1370af6.zip
Makes a series of non-trivial calls.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/generator.ml12
-rw-r--r--src/guestfs-actions.c6
-rw-r--r--src/guestfs.c13
-rw-r--r--src/guestfs_protocol.c10
-rw-r--r--src/guestfs_protocol.h8
-rw-r--r--src/guestfs_protocol.x6
6 files changed, 46 insertions, 9 deletions
diff --git a/src/generator.ml b/src/generator.ml
index 8588cf31..f3e53cd9 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -208,6 +208,12 @@ enum guestfs_message_status {
GUESTFS_STATUS_ERROR = 1
};
+const GUESTFS_ERROR_LEN = 256;
+
+struct guestfs_message_error {
+ string error<GUESTFS_ERROR_LEN>; /* error message */
+};
+
struct guestfs_message_header {
unsigned prog; /* GUESTFS_PROGRAM */
unsigned vers; /* GUESTFS_PROTOCOL_VERSION */
@@ -239,10 +245,10 @@ and generate_client_actions () =
pr "struct %s_rv {\n" shortname;
pr " int err_code; /* 0 OK or -1 error */\n";
pr " int serial; /* serial number of reply */\n";
- pr " char err_str[256]; /* error from daemon */\n";
+ pr " char err_str[GUESTFS_ERROR_LEN]; /* error from daemon */\n";
(match style with
| (Err, _) -> ()
- (* | _ -> pr " struct %s_ret ret;\n" name; *)
+ (* | _ -> pr " struct %s_ret ret;\n" name; REMEMBER TO MEMSET *)
);
pr "};\n\n";
@@ -366,6 +372,8 @@ and generate_daemon_actions () =
(match style with
| (_, P0) -> ()
| (_, args) ->
+ pr " memset (&args, 0, sizeof args);\n";
+ pr "\n";
pr " if (!xdr_guestfs_%s_args (xdr_in, &args)) {\n" name;
pr " reply_with_error (\"%s: daemon failed to decode procedure arguments\");\n" name;
pr " return;\n";
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c
index 12ae6028..f6130d36 100644
--- a/src/guestfs-actions.c
+++ b/src/guestfs-actions.c
@@ -22,7 +22,7 @@
struct mount_rv {
int err_code; /* 0 OK or -1 error */
int serial; /* serial number of reply */
- char err_str[256]; /* error from daemon */
+ char err_str[GUESTFS_ERROR_LEN]; /* error from daemon */
};
static void mount_cb (guestfs_h *g, void *data, XDR *xdr)
@@ -78,7 +78,7 @@ int guestfs_mount (guestfs_h *g,
struct sync_rv {
int err_code; /* 0 OK or -1 error */
int serial; /* serial number of reply */
- char err_str[256]; /* error from daemon */
+ char err_str[GUESTFS_ERROR_LEN]; /* error from daemon */
};
static void sync_cb (guestfs_h *g, void *data, XDR *xdr)
@@ -127,7 +127,7 @@ int guestfs_sync (guestfs_h *g)
struct touch_rv {
int err_code; /* 0 OK or -1 error */
int serial; /* serial number of reply */
- char err_str[256]; /* error from daemon */
+ char err_str[GUESTFS_ERROR_LEN]; /* error from daemon */
};
static void touch_cb (guestfs_h *g, void *data, XDR *xdr)
diff --git a/src/guestfs.c b/src/guestfs.c
index 309cd15b..6de631ff 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -170,6 +170,11 @@ guestfs_create (void)
str = getenv ("LIBGUESTFS_DEBUG");
g->verbose = str != NULL && strcmp (str, "1") == 0;
+ /* Start with large serial numbers so they are easy to spot
+ * inside the protocol.
+ */
+ g->msg_next_serial = 0x00123400;
+
return g;
}
@@ -862,13 +867,13 @@ sock_read_event (void *data, int watch, int fd, int events)
goto cleanup;
}
- if (g->msg_in_size < len) return; /* Need more of this message. */
+ if (g->msg_in_size-4 < len) return; /* Need more of this message. */
/* This should not happen, and if it does it probably means we've
* lost all hope of synchronization.
*/
- if (g->msg_in_size > len) {
- error (g, "len = %d, but msg_in_size = %d", len, g->msg_in_size);
+ if (g->msg_in_size-4 > len) {
+ error (g, "len = %d, but msg_in_size-4 = %d", len, g->msg_in_size-4);
goto cleanup;
}
@@ -944,7 +949,7 @@ sock_write_event (void *data, int watch, int fd, int events)
return;
if (g->verbose)
- fprintf (stderr, "sock_write_event: done writing, switching back to reading events\n", n);
+ fprintf (stderr, "sock_write_event: done writing, switching back to reading events\n");
free (g->msg_out);
g->msg_out_pos = g->msg_out_size = 0;
diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c
index 8a590852..aa5f4e33 100644
--- a/src/guestfs_protocol.c
+++ b/src/guestfs_protocol.c
@@ -58,6 +58,16 @@ xdr_guestfs_message_status (XDR *xdrs, guestfs_message_status *objp)
}
bool_t
+xdr_guestfs_message_error (XDR *xdrs, guestfs_message_error *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->error, GUESTFS_ERROR_LEN))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_message_header (XDR *xdrs, guestfs_message_header *objp)
{
register int32_t *buf;
diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h
index 562d72fc..f8c80439 100644
--- a/src/guestfs_protocol.h
+++ b/src/guestfs_protocol.h
@@ -47,6 +47,12 @@ enum guestfs_message_status {
GUESTFS_STATUS_ERROR = 1,
};
typedef enum guestfs_message_status guestfs_message_status;
+#define GUESTFS_ERROR_LEN 256
+
+struct guestfs_message_error {
+ char *error;
+};
+typedef struct guestfs_message_error guestfs_message_error;
struct guestfs_message_header {
u_int prog;
@@ -66,6 +72,7 @@ extern bool_t xdr_guestfs_touch_args (XDR *, guestfs_touch_args*);
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*);
+extern bool_t xdr_guestfs_message_error (XDR *, guestfs_message_error*);
extern bool_t xdr_guestfs_message_header (XDR *, guestfs_message_header*);
#else /* K&R C */
@@ -74,6 +81,7 @@ extern bool_t xdr_guestfs_touch_args ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
+extern bool_t xdr_guestfs_message_error ();
extern bool_t xdr_guestfs_message_header ();
#endif /* K&R C */
diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x
index 1641b3d1..106bb606 100644
--- a/src/guestfs_protocol.x
+++ b/src/guestfs_protocol.x
@@ -56,6 +56,12 @@ enum guestfs_message_status {
GUESTFS_STATUS_ERROR = 1
};
+const GUESTFS_ERROR_LEN = 256;
+
+struct guestfs_message_error {
+ string error<GUESTFS_ERROR_LEN>; /* error message */
+};
+
struct guestfs_message_header {
unsigned prog; /* GUESTFS_PROGRAM */
unsigned vers; /* GUESTFS_PROTOCOL_VERSION */