WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH 2 of 2] Add support to libxl to trigger power or

To: Paul Durrant <paul.durrant@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes
From: Vincent Hanquez <vincent.hanquez@xxxxxxxxxxxxx>
Date: Wed, 13 Jan 2010 11:00:48 +0000
Cc: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Wed, 13 Jan 2010 03:01:14 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <679f0a189c7280053cc1.1263377772@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <679f0a189c7280053cc1.1263377772@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109)
Paul Durrant wrote:
# HG changeset patch
# User Paul Durrant <paul.durrant@xxxxxxxxxx>
# Date 1263377694 0
# Node ID 679f0a189c7280053cc172d1ed80b6312702f4d8
# Parent  cdf348c11aba31171bdc838ffe3a457acab0f7de
Add support to libxl to trigger power or sleep button pushes
in HVM guests.

Thanks !

Acked-by: Vincent Hanquez <vincent.hanquez@xxxxxxxxxxxxx>

minor comment inline (but can be applied nonetheless):

+void button_press(char *p, char *b)
+{
+    struct libxl_ctx ctx;
+    uint32_t domid;
+    libxl_button button;
+
+    libxl_ctx_init(&ctx, LIBXL_VERSION);

ctx_init can fails in bad situation; it is always better to check the return value just in case.

+    libxl_ctx_set_log(&ctx, log_callback, NULL);
+
+    if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", p);
+        exit(2);
+    }
+
+    if (!strcmp(b, "power")) {
+        button = POWER_BUTTON;
+    } else if (!strcmp(b, "sleep")) {
+        button = SLEEP_BUTTON;
+    } else {
+        fprintf(stderr, "%s is an invalid button identifier\n", b);
+        exit(2);
+    }
+
+    libxl_button_press(&ctx, domid, button);
+}
+

and while it doesn't matter because the program is short lived, you're suppose to call libxl_ctx_free when you're done with libxl.

--
Vincent Hanquez

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel