xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Dario Faggioli <dario.faggioli@citrix.com>
To: Juergen Gross <jgross@suse.com>, xen-devel@lists.xen.org
Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com
Subject: Re: [PATCH v2] libxl: add "xl qemu-monitor-command"
Date: Tue, 6 Sep 2016 10:31:11 +0200	[thread overview]
Message-ID: <1473150671.19612.78.camel@citrix.com> (raw)
In-Reply-To: <1473084701-23694-1-git-send-email-jgross@suse.com>


[-- Attachment #1.1: Type: text/plain, Size: 3445 bytes --]

On Mon, 2016-09-05 at 16:11 +0200, Juergen Gross wrote:
> diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
> @@ -1103,14 +1103,48 @@ int libxl__qmp_x_blockdev_change(libxl__gc
> *gc, int domid, const char *parent,
>      return qmp_run_command(gc, domid, "x-blockdev-change", args,
> NULL, NULL);
>  }
>  
> -int libxl__qmp_hmp(libxl__gc *gc, int domid, const char
> *command_line)
> +static int hmp_callback(libxl__qmp_handler *qmp,
> +                        const libxl__json_object *response,
> +                        void *opaque)
> +{
> +    char **output = opaque;
> +    GC_INIT(qmp->ctx);
> +    int rc = 0;
> +
I'm probably being a bit picky, but libxl's CODING_STYLE says rc should
not be initialized.

> +    if (!output)
> +        goto out;
> +
> +    *output = NULL;
> +
> +    if (libxl__json_object_is_string(response)) {
> +        *output = libxl__strdup(gc,
> libxl__json_object_get_string(response));
> +        goto out;
> +    }
> +
> +    LOG(ERROR, "Response has unexpected format");
> +    rc = ERROR_FAIL;
> +
> +out:
> +    return rc;
> +}
> +
Also, aren't we missing calling GC_FREE on the out path?

> +int libxl__qmp_hmp(libxl__gc *gc, int domid, const char
> *command_line,
> +                   char **output)
>  {
>      libxl__json_object *args = NULL;
>  
>      qmp_parameters_add_string(gc, &args, "command-line",
> command_line);
>  
>      return qmp_run_command(gc, domid, "human-monitor-command", args,
> -                           NULL, NULL);
> +                           hmp_callback, output);
> +}
> +
> +int libxl_qemu_monitor_command(libxl_ctx *ctx, uint32_t domid,
> +                               const char *command_line, char
> **output)
> +{
> +    GC_INIT(ctx);
> +
> +    return libxl__qmp_hmp(gc, domid, command_line, output);
>
 GC_FREE; again ?

>  }
> 

> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> @@ -9536,6 +9536,33 @@ int main_psr_hwinfo(int argc, char **argv)
>  
>  #endif
>  
> +int main_qemu_monitor_command(int argc, char **argv)
> +{
> +    int opt;
> +    uint32_t domid;
> +    char *cmd;
> +    char *output;
> +    int ret;
> +
> +    SWITCH_FOREACH_OPT(opt, "", NULL, "qemu-monitor-command", 2) {
> +        /* No options */
> +    }
> +
> +    domid = find_domain(argv[optind]);
> +    cmd = argv[optind + 1];
> +
> +    if (argc - optind > 2) {
> +        fprintf(stderr, "Invalid arguments.\n");
> +        return 1;
> +    }
> +
> +    ret = libxl_qemu_monitor_command(ctx, domid, cmd, &output);
> +    if (!ret && output)
> +        printf("%s\n", output);
> +
> +    return ret;
>
Things are not fully consistent yet, but there's an ongoing effort for
having xl terminate with either EXIT_SUCCESS or EXIT_FAILURE. Can you
use them when exit()-ing or, like in this case, returning from a
main_foo() function?

Regards,
Dario
-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-09-06  8:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-05 14:11 [PATCH v2] libxl: add "xl qemu-monitor-command" Juergen Gross
2016-09-06  8:31 ` Dario Faggioli [this message]
2016-09-06  9:58   ` Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473150671.19612.78.camel@citrix.com \
    --to=dario.faggioli@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jgross@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).