[libvirt] [PATCH v3 1/6] virCommand: Introduce virCommandDoAsyncIO

Michal Privoznik mprivozn at redhat.com
Tue Feb 5 14:55:54 UTC 2013


On 04.02.2013 16:47, Peter Krempa wrote:
> On 02/04/13 15:56, Michal Privoznik wrote:
>> 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 |   1 +
>>   src/util/vircommand.c    | 308 ++++++++++++++++++++++++++++++++++++++++++++---
>>   src/util/vircommand.h    |   1 +
>>   3 files changed, 293 insertions(+), 17 deletions(-)
>>

> 
> ACK with the two nits fixed. ACKs on the unchanged patches from the last
> time still stand.
> 
> Peter

Thanks, fixed and pushed.

Michal




More information about the libvir-list mailing list