]> git.ipfire.org Git - thirdparty/libvirt.git/commit
virCommand: Introduce virCommandDoAsyncIO
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 16 Jan 2013 10:33:17 +0000 (11:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 5 Feb 2013 14:45:21 +0000 (15:45 +0100)
commit68fb755002da73db4dad1f2ec41bfa317855c206
treec1da901fa2b1fbf44c854776de18037662b90a70
parent8a3cf528e52431a257eaaf15aab6f0839c7c026b
virCommand: Introduce virCommandDoAsyncIO

Currently, if we want to feed stdin, or catch stdout or stderr of a
virCommand we have to use virCommandRun(). When using virCommandRunAsync()
we have to register FD handles by hand. This may lead to code duplication.
Hence, introduce an internal API, which does this automatically within
virCommandRunAsync(). The intended usage looks like this:

    virCommandPtr cmd = virCommandNew*(...);
    char *buf = NULL;

    ...

    virCommandSetOutputBuffer(cmd, &buf);
    virCommandDoAsyncIO(cmd);

    if (virCommandRunAsync(cmd, NULL) < 0)
        goto cleanup;

    ...

    if (virCommandWait(cmd, NULL) < 0)
        goto cleanup;

    /* @buf now contains @cmd's stdout */
    VIR_DEBUG("STDOUT: %s", NULLSTR(buf));

    ...

cleanup:
    VIR_FREE(buf);
    virCommandFree(cmd);

Note, that both stdout and stderr buffers may change until virCommandWait()
returns.
src/libvirt_private.syms
src/util/vircommand.c
src/util/vircommand.h