Coverage Report

Created: 2025-04-22 06:16

/src/qubes-os/qubes-core-qrexec/libqrexec/txrx-vchan.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * The Qubes OS Project, http://www.qubes-os.org
3
 *
4
 * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 *
20
 */
21
22
#include <unistd.h>
23
#include <stdio.h>
24
#include <stdlib.h>
25
#include <signal.h>
26
#include <errno.h>
27
#include <libvchan.h>
28
#include <assert.h>
29
30
#include "libqrexec-utils.h"
31
32
int ppoll_vchan(libvchan_t *ctrl, struct pollfd *fds, size_t nfds,
33
0
                struct timespec *timeout, const sigset_t *sigmask) {
34
0
    struct timespec zero_timeout = { 0, 0 };
35
0
    int ret;
36
37
0
    assert(nfds >= 1);
38
0
    if (libvchan_data_ready(ctrl) > 0) {
39
        /* check for other FDs, but exit immediately */
40
0
        ret = ppoll(fds, nfds, &zero_timeout, sigmask);
41
0
    } else {
42
0
        ret = ppoll(fds, nfds, timeout, sigmask);
43
0
    }
44
45
    /* clear event pending flag, this shouldn't block */
46
0
    if (ret > 0 && fds[0].revents)
47
0
        libvchan_wait(ctrl);
48
49
0
    return ret;
50
0
}
51
52
0
int write_vchan_all(libvchan_t *vchan, const void *data, size_t size) {
53
0
    size_t pos;
54
0
    int ret;
55
56
0
    pos = 0;
57
0
    while (pos < size) {
58
0
        ret = libvchan_write(vchan, data+pos, size-pos);
59
0
        if (ret < 0)
60
0
            return 0;
61
0
        pos += ret;
62
0
    }
63
0
    return 1;
64
0
}
65
66
2.58k
int read_vchan_all(libvchan_t *vchan, void *data, size_t size) {
67
2.58k
    size_t pos;
68
2.58k
    int ret;
69
70
2.58k
    pos = 0;
71
4.32k
    while (pos < size) {
72
1.77k
        ret = libvchan_read(vchan, data+pos, size-pos);
73
1.77k
        if (ret < 0)
74
34
            return 0;
75
1.73k
        pos += ret;
76
1.73k
    }
77
2.55k
    return 1;
78
2.58k
}