[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.