From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vincent Hanquez Subject: Re: [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes Date: Wed, 13 Jan 2010 11:00:48 +0000 Message-ID: <4B4DA7E0.6050400@eu.citrix.com> References: <679f0a189c7280053cc1.1263377772@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <679f0a189c7280053cc1.1263377772@localhost.localdomain> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Paul Durrant Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org Paul Durrant wrote: > # HG changeset patch > # User Paul Durrant > # 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 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