Duplicate stdout and stderr from fork process to files

可紊 提交于 2019-12-02 10:02:34

Using tee and splice to write data from a handle to multiple other handles:

// Needs at least two targets, sentinel is INVALID_HANDLE_VALUE
int push_to_all(int source, ssize_t count, ...) {
    va_list vl;
    va_start(vl, count);
    int target = va_arg(vl, int), next = va_arg(vl, int);
    count = tee(source, target, count, SPLICE_F_NONBLOCK);
    if(count <= 0) { va_end(vl); return count; }
    while((target = next, next = va_arg(vl, int)) > 0) {
        tee(source, target, count, 0);
    va_end(vl);
    return splice(source, 0, target, 0, count, 0);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!