On 10/22/2010 01:46 PM, Michael Roth wrote:
Add RPC to view guest dmesg output.
Signed-off-by: Michael Roth<mdr...@linux.vnet.ibm.com>
---
virtagent-daemon.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
virtagent-daemon.h | 1 +
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/virtagent-daemon.c b/virtagent-daemon.c
index fad0f64..6aaa987 100644
--- a/virtagent-daemon.c
+++ b/virtagent-daemon.c
@@ -72,6 +72,48 @@ EXIT_CLOSE_BAD:
return result;
}
+/* getdmesg(): return dmesg output
+ * rpc return values:
+ * - dmesg output as a string
+ */
+static xmlrpc_value *getdmesg(xmlrpc_env *env,
+ xmlrpc_value *param,
+ void *user_data)
+{
+ char *dmesg_buf = NULL, cmd[256];
+ char c;
+ int pos = 0;
+ xmlrpc_value *result = NULL;
+ FILE *pipe;
+
+ dmesg_buf = qemu_mallocz(VA_DMESG_LEN + 2048);
+ sprintf(cmd, "dmesg -s %d", VA_DMESG_LEN);
+
+ //pipe = popen(cmd, "r");
+ pipe = popen("dmesg -s 16000", "r");
+ if (pipe == NULL) {
+ LOG("popen failed: %s", strerror(errno));
+ xmlrpc_faultf(env, "popen failed: %s", strerror(errno));
+ goto EXIT_NOCLOSE;
+ }
+
+ while ((c = fgetc(pipe)) != EOF&& pos< VA_DMESG_LEN) {
+ dmesg_buf[pos] = c;
+ pos++;
+ }
fgetc seems a bit odd here. Why not fread?
Regards,
Anthony Liguori
+ dmesg_buf[pos++] = '\0';
+ TRACE("dmesg:\n%s", dmesg_buf);
+
+ result = xmlrpc_build_value(env, "s", dmesg_buf);
+ pclose(pipe);
+EXIT_NOCLOSE:
+ if (dmesg_buf) {
+ qemu_free(dmesg_buf);
+ }
+
+ return result;
+}
+
static int va_accept(int listen_fd) {
struct sockaddr_in saddr;
struct sockaddr *addr;
@@ -101,6 +143,8 @@ typedef struct RPCFunction {
static RPCFunction guest_functions[] = {
{ .func = getfile,
.func_name = "getfile" },
+ { .func = getdmesg,
+ .func_name = "getdmesg" },
{ NULL, NULL }
};
static RPCFunction host_functions[] = {
@@ -165,6 +209,7 @@ int va_server_loop(int listen_fd, bool is_host)
XMLRPC_MEMBLOCK_FREE(char, rpc_response);
out:
closesocket(fd);
+ xmlrpc_env_clean(&env);
}
return 0;
diff --git a/virtagent-daemon.h b/virtagent-daemon.h
index bb197d0..adcbc9a 100644
--- a/virtagent-daemon.h
+++ b/virtagent-daemon.h
@@ -16,5 +16,6 @@
#define HOST_AGENT_PATH "/tmp/virtagent-host.sock"
#define VA_GETFILE_MAX 1<< 30
#define VA_FILEBUF_LEN 16384
+#define VA_DMESG_LEN 16384
int va_server_loop(int listen_fd, bool is_host);