Return-path: <chris@arachsys.com>
Envelope-to: chris+sent@arachsys.com
Received: from arachsys.demon.co.uk ([83.104.159.199] helo=miranda.arachsys.com)
	by alpha.arachsys.com with esmtpa (Exim 4.52)
	id 1L4v82-0001vY-9D; Tue, 25 Nov 2008 10:26:46 +0000
Received: from chris by miranda.arachsys.com with local (Exim 4.52)
	id 1L4v82-0002E2-2Y; Tue, 25 Nov 2008 10:26:46 +0000
Date: Tue, 25 Nov 2008 10:26:46 +0000
From: Chris Webb <chris@arachsys.com>
To: qemu-devel@nongnu.org, kvm@vger.kernel.org
Cc: Thiemo Seufer <ths@networkno.de>
Subject: [PATCH v2] Accept password as an argument to 'change vnc password'
Message-ID: <20081125102646.GK2380@arachsys.com>
References: <20081123113147.GA12832@arachsys.com> <20081123123101.GC17042@networkno.de> <20081125100935.GI2380@arachsys.com> <20081125102502.GJ2380@arachsys.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20081125102502.GJ2380@arachsys.com>
User-Agent: Mutt/1.5.18 (2008-05-17)

Accept password as an argument to 'change vnc password' monitor command

This allows easier use of the change vnc password monitor command from
management scripts, without having to implement expect(1)-like behaviour.

Signed-off-by: Chris Webb <chris@arachsys.com>
---
 monitor.c     |   14 +++++++++-----
 qemu-doc.texi |    8 ++++----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/monitor.c b/monitor.c
index a252838..f6a2783 100644
--- a/monitor.c
+++ b/monitor.c
@@ -428,12 +428,16 @@ static void do_change_block(const char *device, const char *filename, const char
     qemu_key_check(bs, filename);
 }
 
-static void do_change_vnc(const char *target)
+static void do_change_vnc(const char *target, const char *arg)
 {
     if (strcmp(target, "passwd") == 0 ||
 	strcmp(target, "password") == 0) {
 	char password[9];
-	monitor_readline("Password: ", 1, password, sizeof(password));
+	if (arg) {
+	    strncpy(password, arg, sizeof(password));
+	    password[sizeof(password) - 1] = '\0';
+	} else
+	    monitor_readline("Password: ", 1, password, sizeof(password));
 	if (vnc_display_password(NULL, password) < 0)
 	    term_printf("could not set VNC server password\n");
     } else {
@@ -442,12 +446,12 @@ static void do_change_vnc(const char *target)
     }
 }
 
-static void do_change(const char *device, const char *target, const char *fmt)
+static void do_change(const char *device, const char *target, const char *arg)
 {
     if (strcmp(device, "vnc") == 0) {
-	do_change_vnc(target);
+	do_change_vnc(target, arg);
     } else {
-	do_change_block(device, target, fmt);
+	do_change_block(device, target, arg);
     }
 }
 
diff --git a/qemu-doc.texi b/qemu-doc.texi
index 1735d92..ca3b181 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -1233,11 +1233,11 @@ and @var{options} are described at @ref{sec_invocation}. eg
 (qemu) change vnc localhost:1
 @end example
 
-@item change vnc password
+@item change vnc password [@var{password}]
 
-Change the password associated with the VNC server. The monitor will prompt for
-the new password to be entered. VNC passwords are only significant upto 8 letters.
-eg.
+Change the password associated with the VNC server. If the new password is not
+supplied, the monitor will prompt for it to be entered. VNC passwords are only
+significant up to 8 letters. eg
 
 @example
 (qemu) change vnc password

