From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=34204 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAUoM-00014U-0s for qemu-devel@nongnu.org; Mon, 25 Oct 2010 17:42:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PAUoK-0004lb-Q1 for qemu-devel@nongnu.org; Mon, 25 Oct 2010 17:42:33 -0400 Received: from mail-qy0-f180.google.com ([209.85.216.180]:41482) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PAUoK-0004lW-MV for qemu-devel@nongnu.org; Mon, 25 Oct 2010 17:42:32 -0400 Received: by qyk8 with SMTP id 8so2218391qyk.4 for ; Mon, 25 Oct 2010 14:42:32 -0700 (PDT) Message-ID: <4CC5F9C9.4040402@codemonkey.ws> Date: Mon, 25 Oct 2010 16:42:33 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [RFC][PATCH 07/10] virtagent: add getdmesg RPC References: <1287773165-24855-1-git-send-email-mdroth@linux.vnet.ibm.com> <1287773165-24855-8-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1287773165-24855-8-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, agl@linux.vnet.ibm.com, qemu-devel@nongnu.org, abeekhof@redhat.com On 10/22/2010 01:46 PM, Michael Roth wrote: > Add RPC to view guest dmesg output. > > Signed-off-by: Michael Roth > --- > 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); >