• M
    virCommand: Introduce virCommandDoAsyncIO · 68fb7550
    Michal Privoznik 提交于
    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.
    68fb7550
libvirt_private.syms 42.0 KB